1

Hi a quick help needed in .csv.

How should I add an additional column to present csv file. I have 100 customers information in .csv file. Once application reads a particular line, append a column saying that "this line is read".

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
user1380678
  • 47
  • 1
  • 8
  • 1
    possible duplicate of [Can you recommend a Java library for reading (and possibly writing) CSV files?](http://stackoverflow.com/questions/200609/can-you-recommend-a-java-library-for-reading-and-possibly-writing-csv-files) – Amir Raminfar May 07 '12 at 20:59

2 Answers2

1

Use OpenCSV for writing to csv files, there are many similar third party libraries that you can use.

Rachel
  • 100,387
  • 116
  • 269
  • 365
0

Whether you use a library or make your own parsing function, you'll need to do the following:

  1. Read the file.
  2. Append new column (basically a static string).
  3. Write to file.
user845279
  • 2,794
  • 1
  • 20
  • 38
  • I am able to read the file, but how to append a new column with out using openCsv, because we are not allowed to use. we are using 1.4 java compiler. – user1380678 May 07 '12 at 21:01
  • Just append `",This line is read"` to each line you've read and write it to another file. Remember, csv file can contain new-line characters within the data as long as it is surrounded by quotes (that's why people recommend openCsv). – user845279 May 07 '12 at 21:06
  • Thanks for getting back to me. can you give me code after reading and writing to csv file. Here are the steps what i am doing. 1. connecting to server 2. remove the .csv file from server and move to my class path 3. Now, the csv file in the class path needs to be edited as status=readline 4. I need to check everytime if line is read or not 5. If read and end of file -- move to archive location So is it a good idea to write to new file instead of updating same file – user1380678 May 07 '12 at 21:09
  • I thought i just did. Look at [this](http://www.kodejava.org/examples/241.html) example. If you change line 24 to `String line = scanner.nextLine() + ",This line is read";` It will do the job for a simple CSV file. Please tag your questions #homework and you'll get better answers. – user845279 May 07 '12 at 21:18