• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

reading from a file

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bad form on my part-- StringTokeniszer.nexttoken.()trim() will return String.

John
 
Master Rancher
Posts: 5112
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
We don't have time to be charming! Quick, read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic