This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Actually I searched and didn't find any duplicates of this post.
Read carefully what the String#startsWith() method takes as its parameters. And, as people have said, please post the code and your results.
Tran Tuan Hung
Joined: Apr 08, 2007
Ok thanks very much Here is my code This is FileFormat.java
Here is class ReadFile.java to read the text file.
Now I have two questions: 1/ When I run the program, it appear the error, help me to correct it.
java.lang.NumberFormatException: For input string: "123 test1y" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:456) at java.lang.Integer.parseInt(Integer.java:497) at com.goodsw.myroute.ReadFile.read(ReadFile.java:24) at com.goodsw.myroute.ReadFile.main(ReadFile.java:40)
2/ In the my code, i only set value of x, y , z, t (format.setX(), format.setY()�..) when line startWith(�123�), but I have many, many lines something like this it is line that start with an integer number with three digits: So what kind of regex I can try? The idea as following:
Please help me to slove my problem, thanks very much.
Joined: Oct 13, 2005
A NumberFormatException thrown by Integer#parseInt means that whatever you have passed to it is not an integer when printed out. Please check that the lines are actually delimited by tabs. Try the standard regex for whitespace as a delimiter instead of "\\t"; I think it is "\\s", but not certain.
And why are you calling the argument to String#startsWith "regex"? I have already mentioned that point.