read a file
I would like to read a flat file on the unix system. However, I got this error when running the java:
$ java ReadFile fs_sample
Exception in thread "main" java.lang.NoClassDefFoundError: ReadFile
Can anyone help me? Thanks a lot in advance.
Here is theReadFile.java:
import java.io.*;
public class ReadFile {
public static void main (String [] args) {
//create a file
File file = new File(args[0]);
System.out.println("Filename is " + args[0]);
try {
//create a buffered reader to read each line from a file.
BufferedReader in = new BufferedReader(new FileReader(file));
String s;
//read each line from the file
s=in.readLine();
while (s != null) {
System.out.println("Read: " +s);
s=in.readLine();
}
//close the buffered reader
in.close();
}
catch (FileNotFoundException el) {
//if the file does not exist
System.out.println("File not found: "+file);
}
catch (IOException e2) {
//catch other IO errors
e2.printStackTrace();
}
}
}

