/* package whatever; // don't place package name! */
import java.util.*;
import java.io.*;
/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
{
char input1;
ArrayList<String> list1 = new ArrayList<String>();
try
{
// print out the menu
// rt.exec( "rundll32 url.dll,FileProtocolHandler " + "http://www.google.com");
printMenu();
// create a BufferedReader object to read input from a keyboard
do
{
System.
out.
println("\nWhat action would you like to perform?"); line = stdin.readLine().trim(); //read a line
input1 = line.charAt(0);
if (line.length() == 1) //check if a user entered only one character
{
switch (input1)
{
case 'A': //Add address process to array
System.
out.
println("\nPlease enter a web address to add to list:\n"); String str1
= stdin.
readLine().
trim(); if(str1.startsWith("http://www.") || str1.startsWith("https://www."))
list1.add(str1);
else
{
System.
out.
println("Please enter a valid web address (starting with http:// or https://)."); }
break;
case 'D': //Show current list
System.
out.
println(list1.
toString()); break;
case 'E': //Execute current list
//rt.exec( "rundll32 url.dll,FileProtocolHandler " + "http://w...content-available-to-author-only...t.net");
for(int i = 0; i < list1.size(); i++)
{
Process p1
= Runtime.
getRuntime().
exec("cmd /c start " + list1.
get(i
)); }
break;
case 'R': //Read list from file
System.
out.
println("\nPlease enter the filename to read: "); {
filename = stdin.readLine().trim();
System.
out.
println("The filename am trying check is"+filename
); }
try
{
line = inFile.readLine();
while(line != null)
{
if(line.startsWith("http://www.") == false || line.startsWith("https://www.") == false)
System.
out.
println("Error: File not in proper format."); else
list1.add(line);
}
System.
out.
println(filename
+ " was read."); }
{
System.
out.
println("The file " + filename
+ " was not found."); break;
}
{
System.
out.
println("Error. " + exception
); }
finally
{
if(inFile!=null)
inFile.close();
}
break;
case '?': //Display Menu
printMenu();
break;
case 'Q': //Quit
System.
out.
println("Goodbye!"); }//end switch
}//end if
else
System.
out.
print("Unknown action\n"); }//end do
while (input1 != 'Q' || line.length() != 1);
}
{
System.
out.
println("Error: " + e1
); }
}//end main
public static void printMenu()
{
System.
out.
print("Choice\t\tAction\n" + "------\t\t------\n" +
"A\t\tAdd Web Address to List\n" +
"D\t\tDisplay Current List\n" +
"E\t\tExecute Current List\n" +
"R\t\tRead List from File\n" +
"?\t\tDisplay Menu\n" +
"Q\t\tQuit\n");
}//end of printMenu()
}