Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
Rancher
Posts: 4739
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.
 
I love a good mentalist. And so does this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic