This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Reading a file and getting run time error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading a file and getting run time error" Watch "Reading a file and getting run time error" New topic
Author

Reading a file and getting run time error

Jithesh Kumar
Ranch Hand

Joined: Mar 09, 2010
Posts: 46
when i am reading a file and converting the string to integer it is giving me
java.lang.NumberFormatException:For input string:"" run time error

this is the code

BufferedReader leagueReader=new BufferedReader(new

FileReader(leagueFile));
String record;
while((record=leagueReader.readLine())!=null){
String del="|";
String[] fields=record.split(del);
int objectID=Integer.parseInt(fields[0]);---this line is giving the error.
int year=Integer.parseInt(fields[1]);
String season=fields[2];
String title=fields[3];
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

bon jith wrote:when i am reading a file and converting the string to integer it is giving me
java.lang.NumberFormatException:For input string:"" run time error

this is the code



Try outputing record and/or fields[0] on each loop in after the split() command. You will then probably see a missing piece of data. You will have to do a check on fields[0] to make sure it is not a blank string.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading a file and getting run time error
 
Similar Threads
travel agent - java writing to file via user input
unable to exit program..
insertion and deletion of record from a text file
Reg:Executing Commands
travel agent - outofmemory heap error