import java.net.*;
import java.io.*;
import java.util.*;
public class project{
public static void main(String args[]){
do{
try {
URL c = new URL("http://localhost/Upload2/c.txt");
URL cinfo = new URL("http://localhost/Upload2/cinfo.txt");
Scanner c2 = new Scanner(c.openStream());
Scanner cinfo2 = new Scanner(cinfo.openStream());
String c3 = c2.nextLine();
String cinfo3 = cinfo2.nextLine();
if ("commandline".compareTo(c3) == 0){
Runtime.getRuntime().exec(cinfo3);
if ("idle".compareTo(c3) == 0){
System.out.println("Waiting for a command.");
}
if ("print".compareTo(c3) == 0){
System.out.println(cinfo3);
}
}
}
catch(IOException ex) {
ex.printStackTrace();
}
} while(true);
}
}
This is my current code. However, none of the if statements work! For example, even when the text file says “idle”, nothing happened! I even tried to print the value of the text file and it worked (it said idle).
The first
if:if ("commandline"...)encapsulates the following 2 of them inside. This means that if the firstifevaluates tofalse, the following ones will never execute.