How do I import the java CSVFileReader and how do I use it?
Printable View
How do I import the java CSVFileReader and how do I use it?
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:
where strFileLocation = the location of the file you want to openCode:Process p = Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " +
"strFileLocation");
Regards,
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.
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++;
}
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.Quote:
Originally Posted by Greyskull
This means any kind of values
Sorry i think i said that wrong :blush: . 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...Quote:
Originally Posted by ComputerJy
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
So do you guys know where I can get a class that works?
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,
Cool, that looks pretty solid. I used this one, it works great
http://opencsv.sourceforge.net/
Glad to hear it :thumb: Don't forget to resolve the thread ;)