Hi, I'm a beginner with Java and I've encountered some trouble with simple I/O. Thing is, I have to enable the command line and write a file name of a textfile which holds a simple number. That number I have to get from the file and into JGrasp and print it out.
The problem occurs when I print it out and the number is 49 or -1 and not 15 which is the number that's actually in the file. I've experimented with the debugger feature and it seems that it finds the number somewhere after looking in the text file. This is really confusing for me, and any help would be really nice.
import java.io.*;
public class HippityHop {
public static void main(String [] args) {
try{
String var = args[0];
FileReader in = new FileReader(var);
int chr = in.read();
while(chr != -1) {
chr = in.read();
}
System.out.println(chr);
in.close();
}//end of try
catch(FileNotFoundException fnfe){
fnfe.printStackTrace();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
}//end main
}//end class