• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading from a file  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a txt file which stores timetable data in this format:

flightnumber, departuredate, departuretime, avaliableseats

so, at the moment the file looks like this:

001, 01.01.05, 09.00, 10

I need to read in this data and then display it. At the moment my code to do this looks like this:



It all compiles etc but wont read in the values. Also, if I wanted to change one of the values in the file (like avaliableSeats ) how would I do this without updating the whole file (ie, just update the one value as opposed to the whole file).

J
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jambeard lewistrix:
It all compiles etc


I don't believe you. The code you've posted will not compile.


This is bad form too. You are silently ignoring a possible IOExxception. Print the stack trace.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the String tokenizer returns String on the return. Your code shouldn't even compile.

Try changing the int departureDate --- String departureDate.

John
 
John Martinson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bad form on my part-- StringTokeniszer.nexttoken.()trim() will return String.

John
 
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To update a file inplace without having to copy the whole file requires that the new data be exactly the same size in bytes as the old data.
Use the RandomAccessFile to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!