Hello everyone,
I made an application that loads all the numbers from a .txt file into a Vector by using the FileReader class.
And it works fine when I only add 1 number in there, but as soon as I add another, my application returns a java.lang.NumberFormatException.
Here's my "process()" method, with the line the error occurs in highlighted in red:
/**
* Processes all data.
*/
public void process(){
try{
File file = new File("./data/Illegal IDs.txt");
FileReader reader = new FileReader(file);
while(reader.read() != -1){
char[] buffer = new char[(int)file.length()];
reader.read(buffer);
String text = new String(buffer).trim();
String[] line = text.split("\n");
for(int i = 0; i < line.length; i++){
{color:#ff0000}int ID = Integer.parseInt(line);{color}
addValue(ID);
if(isIllegal(ID)){
System.out.print("Illegal ID " + ID + " was found.\n");
}else{
System.out.print(ID + " is not illegal.");
}
}
}
}catch(IOException ioe){
ioe.printStackTrace();
}
}
And this is my Runtime output:
{CODE}
run:
Exception in thread "main" java.lang.NumberFormatException: For input string: "4151"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.parseInt(Integer.java:499)
at filter.Filter.process(Filter.java:44)
at filter.Main.main(Main.java:22)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
{CODE}
If you need any more info, just ask for it, and I'll provide it :).
Please help me :D.