I have learned Java for about a month and am currently learning I/O of Java but I have encountered some problems. Below is a simply toy code to practice with the Inputstream.
import java.io.*;
public class IOTest{
public static void main(String[] args) throws IOException{
InputStream in;
in = new FileInputStream(args[0]);
int total = 0;
while (in.read() != -1)
total++;
System.out.println(total + " bytes");
}
}
The above code compiles Okay. The purpose of this code is to simply calculate how many bytes in the arguments. However, when I run the compiled code with arguments, for example:
java IOTest firstTrial
The system gives the following Exception message:
Exception in thread "main" java.io.FileNotFoundException: firstTrial <The system
cannot find the file specified>
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init><Unknown Source>
at java.io.FileInputStream.<init><Unknown Source>
at IOTest.main<IOTest.java:8>
Please help point out how was the exception thrown?
One extra question is I am using Eclipse for java programming. What is the End-of-Input character in Eclipse for Java? Thanks