|
-
Jan 31st, 2008, 01:47 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Java CSVFileReader
How do I import the java CSVFileReader and how do I use it?
-
Jan 31st, 2008, 04:09 PM
#2
Hyperactive Member
Re: Java CSVFileReader
Well what kind of things you want to do with the CSV file?
You simply need to add the relevant header file. Depending on the method chosen.
http://www.exampledepot.com/egs/java...ParseLine.html - this mite be of help
If you simply want to open the actual CSV file then 'import java.io.*;' should do the trick with the following code:
Code:
Process p = Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " +
"strFileLocation");
where strFileLocation = the location of the file you want to open
Regards,
Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered 
If someone helped you today then please consider rating their post.
-
Jan 31st, 2008, 04:16 PM
#3
Thread Starter
Hyperactive Member
Re: Java CSVFileReader
the problem is when Im tokenizing the line with commas, im missing cells with commas in them. The way csv files are created is if there is a comma in the cell then quotes are put around the token. I read that there is a built in way of taking care of this common probelm in php and im sure something exists with java, i just would like to know what it is and how to use it.
-
Jan 31st, 2008, 04:18 PM
#4
Hyperactive Member
Re: Java CSVFileReader
Here you could also try this out:
Code:
String [][] strNum = new String [30][30];
File f = new File("filename.csv");
BufferedReader br = new BufferedReader(new FileReader(f));
String strLine = null;
int row = 0;
int col = 0;
//read each line of text file
while((strLine = br.readLine()) != null && row < 30)
{
StringTokenizer st = new StringTokenizer(strLine,",");
while (st.hasMoreTokens())
{
//get next token and store it in the array
strNum[row][col] = st.nextToken();
col++;
}
col = 0;
row++;
}
Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered 
If someone helped you today then please consider rating their post.
-
Jan 31st, 2008, 04:19 PM
#5
Hyperactive Member
Re: Java CSVFileReader
not sure whether the above post will help you though (didnt know you had commas in your CSV file)...what kind of data is stored in your CSV?
Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered 
If someone helped you today then please consider rating their post.
-
Jan 31st, 2008, 06:02 PM
#6
Re: Java CSVFileReader
 Originally Posted by Greyskull
not sure whether the above post will help you though (didnt know you had commas in your CSV file)...what kind of data is stored in your CSV?
CSV = Comma Separated Values.
This means any kind of values
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 31st, 2008, 06:10 PM
#7
Hyperactive Member
Re: Java CSVFileReader
 Originally Posted by ComputerJy
CSV = Comma Separated Values.
This means any kind of values
Sorry i think i said that wrong . i knw what CSV file is but what i was trying to say was im not sure how to do it if one of his values contained a comma as i knw that the application will think its the end of line...
Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered 
If someone helped you today then please consider rating their post.
-
Jan 31st, 2008, 06:23 PM
#8
Re: Java CSVFileReader
when using CSV, all commas in original data must be encoded to something like a tag so it can be decoded when reading the file without causing any problems
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 31st, 2008, 07:04 PM
#9
Thread Starter
Hyperactive Member
Re: Java CSVFileReader
So do you guys know where I can get a class that works?
-
Feb 1st, 2008, 06:41 AM
#10
Hyperactive Member
Re: Java CSVFileReader
The following link maybe of help
http://faq.javaranch.com/java/AccessingFileFormats
Under the Excel files, there are three links you could try with CSV files.
tbh, i havent really tried inserting commas to any of the fields stored in a CSV file as i knew i will encounter problems such as this, instead, if i had to store i value containing commas, i will use a database.
Regards,
Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered 
If someone helped you today then please consider rating their post.
-
Feb 1st, 2008, 01:09 PM
#11
Thread Starter
Hyperactive Member
Re: Java CSVFileReader
Cool, that looks pretty solid. I used this one, it works great
http://opencsv.sourceforge.net/
-
Feb 1st, 2008, 03:03 PM
#12
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|