This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes parse a csv file (PLEASE HELP) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "parse a csv file (PLEASE HELP)" Watch "parse a csv file (PLEASE HELP)" New topic
Author

parse a csv file (PLEASE HELP)

s oc
Greenhorn

Joined: Aug 02, 2006
Posts: 5
Hi there,

I am trying to parse a CSV file, I have a program which will read in the contents of the file and display them to the console and i need to parse some of the fields, which I have no idea how to do
I am trying to get the field info into to an SWT table. The csv file I'm trying to parse has some useless information before and after the file info which is numbered [0-n].
I need to get each relevent line and take its individual pieces of data and store them in an array or something so I can put them into my table i.e. '0:' in one tableItem and 'bla.jpg' in the next tableItem.

Any help or code samples would be much appreciated,

Thanks in advance,

Shinny

--START OF CSV FILE--
File: penDriveImage3.001
Start: Wed Aug 02 19:49:44 2006
Length: 992 MB (1040187392 bytes)

Num Name (bs=512) Size File Offset Comment

0: 8426.jpg 5 KB 4314525 (null) /*THESE LINES ARE IN ONE FIELD EACH!?!*
1: 13578.jpg 42 KB 6952364 (null)
2: 13663.jpg 27 KB 6995952 (null)
3: 13791.jpg 26 KB 7061467 (null)
4: 14825.jpg 46 KB 7590486 (null)
5: 16830.jpg 83 KB 8617069 (null)
6: 16999.jpg 36 KB 8703995 (null)
...RANDOM DATA HERE...
--END OF CSV FILE--

--START OF CODE--
package GUI;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadSource
{
public static void main(String[] arguments)
{
try
{
FileReader file = new FileReader("C:\\audit.csv");
BufferedReader buff = new BufferedReader(file);
boolean eof = false;
while(!eof){
String line = buff.readLine();
if(line == null)
eof = true;
else
System.out.println(line);
}
buff.close();
}
catch(IOException e)
{
System.out.println("Error -- " + e.toString());
}
}

}
--END OF CODE--
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8260

First, you don't have a CSV file. CSV stands for "Comma Seperated Value".
Second, Fahd gave you a good answer in your previous post. What don't you understand about his post?
Third, we like to keep things friendly around here so we insist that you use your real name (or at least a real-sounding name). You can change your displayed name here.
[ August 11, 2006: Message edited by: Joe Ess ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24051
    
  13

Closing this; followups here.


[Jess in Action][AskingGoodQuestions]
s oc
Greenhorn

Joined: Aug 02, 2006
Posts: 5
If your not going to be helpful then please don't reply to my post!
AND the name I use is my nickname & isn't far off my real name with soc being my intitials so don't assume that its not friendly!
I wouldn't have reposted if I still didn't have a problem.
The external program I am using is outputting a csv file as above and that's what I have to work with, hence me having such a problem.

Hopefully this doesn't put off anyone else genuinely wanting to help me but I really am stuck.

Thanks in advance to anyone who wants to help,

Shinny
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: parse a csv file (PLEASE HELP)
 
Similar Threads
Anyone help me out with this error
Want to write a combined text file, but nothing happens..
JFileChooser
Parsing a .txt file
Using Swing to display an array from text file issues