fork download
  1. /* package whatever; // don't place package name! */
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. /* The class name doesn't have to be Main, as long as the class is not public. */
  6. class Main
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. char input1;
  11. String line = new String();
  12. ArrayList<String> list1 = new ArrayList<String>();
  13. Runtime rt = Runtime.getRuntime();
  14. String filename = new String();
  15.  
  16. try
  17. {
  18. // print out the menu
  19. // rt.exec( "rundll32 url.dll,FileProtocolHandler " + "http://www.google.com");
  20. printMenu();
  21.  
  22. // create a BufferedReader object to read input from a keyboard
  23. BufferedReader stdin = new BufferedReader (isr);
  24.  
  25. do
  26. {
  27. System.out.println("\nWhat action would you like to perform?");
  28. line = stdin.readLine().trim(); //read a line
  29. input1 = line.charAt(0);
  30. input1 = Character.toUpperCase(input1);
  31. if (line.length() == 1) //check if a user entered only one character
  32. {
  33. switch (input1)
  34. {
  35. case 'A': //Add address process to array
  36. System.out.println("\nPlease enter a web address to add to list:\n");
  37. String str1 = stdin.readLine().trim();
  38. if(str1.startsWith("http://www.") || str1.startsWith("https://www."))
  39. list1.add(str1);
  40. else
  41. {
  42. System.out.println("Please enter a valid web address (starting with http:// or https://).");
  43. }
  44. break;
  45. case 'D': //Show current list
  46. System.out.println(list1.toString());
  47. break;
  48. case 'E': //Execute current list
  49. //rt.exec( "rundll32 url.dll,FileProtocolHandler " + "http://w...content-available-to-author-only...t.net");
  50. for(int i = 0; i < list1.size(); i++)
  51. {
  52. Process p1 = Runtime.getRuntime().exec("cmd /c start " + list1.get(i));
  53. }
  54. break;
  55. case 'R': //Read list from file
  56. System.out.println("\nPlease enter the filename to read: ");
  57. {
  58. filename = stdin.readLine().trim();
  59. System.out.println("The filename am trying check is"+filename);
  60. }
  61. FileReader fr = null;
  62. BufferedReader inFile = null;
  63. try
  64. {
  65. fr = new FileReader(filename);
  66. inFile = new BufferedReader(fr);
  67. line = inFile.readLine();
  68. System.out.println("Test2");
  69. while(line != null)
  70. {
  71. System.out.println("Test3");
  72. if(line.startsWith("http://www.") == false || line.startsWith("https://www.") == false)
  73. System.out.println("Error: File not in proper format.");
  74. else
  75. list1.add(line);
  76. }
  77. System.out.println(filename + " was read.");
  78. }
  79. catch(FileNotFoundException exception)
  80. {
  81. System.out.println("The file " + filename + " was not found.");
  82. break;
  83. }
  84. catch(IOException exception)
  85. {
  86. System.out.println("Error. " + exception);
  87. }
  88. finally
  89. {
  90. if(inFile!=null)
  91. inFile.close();
  92. }
  93.  
  94. break;
  95. case '?': //Display Menu
  96. printMenu();
  97. break;
  98. case 'Q': //Quit
  99. System.out.println("Goodbye!");
  100. System.exit(0);
  101. }//end switch
  102. }//end if
  103. else
  104. System.out.print("Unknown action\n");
  105. }//end do
  106. while (input1 != 'Q' || line.length() != 1);
  107. }
  108.  
  109. catch(IOException e1)
  110. {
  111. System.out.println("Error: " + e1);
  112. }
  113. }//end main
  114. public static void printMenu()
  115. {
  116. System.out.print("Choice\t\tAction\n" +
  117. "------\t\t------\n" +
  118. "A\t\tAdd Web Address to List\n" +
  119. "D\t\tDisplay Current List\n" +
  120. "E\t\tExecute Current List\n" +
  121. "R\t\tRead List from File\n" +
  122. "?\t\tDisplay Menu\n" +
  123. "Q\t\tQuit\n");
  124. }//end of printMenu()
  125.  
  126.  
  127. }
Success #stdin #stdout 0.07s 380160KB
stdin
R
C:/MyFileName
Q
stdout
Choice		Action
------		------
A		Add Web Address to List
D		Display Current List
E		Execute Current List
R		Read List from File
?		Display Menu
Q		Quit

What action would you like to perform?

Please enter the filename to read: 
The filename am trying check isC:/MyFileName
The file C:/MyFileName was not found.

What action would you like to perform?
Goodbye!