.CSV File handling

Hi All,

plz help me again for this job:

ny problem is :

data is comng through internet via socket in csv file.every time data is appended in this file.

my job is everytime thread will checks the file and if any new data come then it display that data into a JTable and save this data into database.

main prob is that i have no idea of dealing with .CSV file.

plz help me soon.

[419 byte] By [kakkar.java@gmail.coma] at [2007-10-3 6:39:58]
# 1

Type in "CSV Format" into ANY search engine.

Why didn't you do any professional research prior to posting? Why? Becuase you'd have done work - and having us tell you the answer would be faster, right?

True, but I am still going to yell at you for doing it.

Anyway, CSV stands for Comma-Seperated Value. The format? Easy, data seperated by a comma (,). Datatype is typically ASCII, as much of it is plain old text or numerical (non-binary) data.

If you have Excel or other spreadsheet program try typing some data and then save it in CSV format, then open it with a word processor. You'll see what the format looks like.

Example:

"Java","Website","http://www.java.com/"

"Sun","Money",9999999999999

Each "record" or row is a new line, while text may or may not be contained by quotes, numerical values are usually without quotes, but everything is seperated by a comma.

watertownjordana at 2007-7-15 1:28:45 > top of Java-index,Core,Core APIs...
# 2
A BIGGER question is why does a host send your program the ENTIRE file - thus repeating the data your program already knows - and not just send updates to that data?
watertownjordana at 2007-7-15 1:28:45 > top of Java-index,Core,Core APIs...
# 3

1. Read each row from CSV file using

FileInputStream fin = new FileInputStream("yourcsv.csv");

InputStreamReader isr = new InputStreamReader(fin);

BufferedReader reader = new BufferedReader( isr );

String row = null;

Vector rows = new Vector();

do

{

row = reader.readLine();

if( row != null )

rows.add(row);

}while( row != null );

2. Retrieve all row from rows Vector and tokenize the string( row );

When you tokenize, string( here row object ), you will get followings:

e.g : if your string is "hello","1998","something".

when you tokenize, using delimiter as ','

you will get

in 1st token => hello

in 2nd token => 1998

in 3rd token => something

3. Now you can continue your work. :)

J-elfa at 2007-7-15 1:28:45 > top of Java-index,Core,Core APIs...
# 4
So what value does the Vector add? and why are there two tests in the do-while loop when one would do?The problem is about the question WTJ asked, and about tokenizing, with and without quotes, not this I/O trivia.
ejpa at 2007-7-15 1:28:45 > top of Java-index,Core,Core APIs...
# 5
There is a good free library for processing csv files at http://ostermiller.org/utils/CSV.html .
sabre150a at 2007-7-15 1:28:45 > top of Java-index,Core,Core APIs...
# 6
> Anyway, CSV stands for Comma-Seperated Value.In non-English versions the actual separating character might be different from comma depending on the OS and/or the Office language.
BIJ001a at 2007-7-15 1:28:45 > top of Java-index,Core,Core APIs...