.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.
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.
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. :)
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 >
