• Post Reply Bookmark Topic Watch Topic
  • New Topic

modify a particular line of a .csv file  RSS feed

 
Narayan Soni
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am supposed to use only .csv file ,in the csv flie each line contains details of a particular flight at a particular date ,so when a new booking is done i need to modify the seat availaibility part of that flight,how to
do this..without creating a temporary file...and just modifying the particular flight line in the original file..?
thanks..in advance for any helpful reply..!!!
 
Liutauras Vilda
Marshal
Posts: 4657
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us what have you done so far and where you stuck?
 
Narayan Soni
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i am not stucked any where..i am doing a project on flight reservation system using .csv file as a database storing the flight detail of a particular flight on a particular date...so when the user books a flight after a search mechanism (its implemented) i need to update the no.of seat available on that flight.so i need to first search that flight detail line in the csv file than as soons as i encounter with that flight
(using flight num and date of dept.) i need to change the value of seats available...the .csv file has the contents in this way....

ORIGIN|DESTINATION|FREQUENCY|FLIGHT NO|DEPARTURE|ARRIVAL|VIA|DATE OF PERATURE|SEATS AVAILABLE
...
...
DELHI|BENGALURU|DAILY|SG 139|04:05 PM|06:50 PM|-|16 AUG 15|15
DELHI|BENGALURU|SUNDAY|SG 135|02:10 PM|05:00 PM|-|15 NOV 15|26
 
Liutauras Vilda
Marshal
Posts: 4657
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, task is semi clear. I'm not clear where the seats availability values comes from?
I don't think you'll get exact solution in here, but you could always show us what have you tried and we'll try to help you if you encounter any difficulties.

But since you wrote:
Narayan Soni wrote:actually i am not stucked any where

Not sure how we can help you?
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to modify the original file you you can use java.io.RandomAccessFile. However, in order for this to work without the risk of overwriting data you need to have fixed width fields for your data.
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras just reminded me there is a FAQ in this subject which can be found at http://www.coderanch.com/how-to/java/EditAnExistingFile
 
Liutauras Vilda
Marshal
Posts: 4657
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And before you do any crazy things, make a copies of your original files - always.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!