Hi...I am new to java......can anyone pls. help me in reading a csv
file using core java.
File path will be send as a paramter.
Pls. let me know in detail.....like opening a file.....moving the
counter.....and reading data on record by record basis.
It wud be of great help if u can provide me with sample code.
Thanks in advance.
Andrew Thompson - 21 Apr 2007 07:00 GMT
>Hi...I am new to java......
A good group for those learning Java is
<http://www.physci.org/codes/javafaq.html#h>
>..can anyone pls. help me in reading a csv
>file using core java.
>File path will be send as a paramter.
>Pls. let me know in detail.....like opening a file.....moving the
>counter.....and reading data on record by record basis.
>It wud be of great help if u can provide me with sample code.
But note that even there, you will need to do
some research and put in some effort, rather
than simply making pleas for someone to
provide 'the codes'.
Further, using an upper case letter consistently at
the start of each sentnce, as well as fully spelling
words such as 'please', 'would' and 'you' will get
you a lot more repsect.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Eric Sosman - 21 Apr 2007 12:44 GMT
>> Hi...I am new to java......
>
[quoted text clipped - 17 lines]
> words such as 'please', 'would' and 'you' will get
> you a lot more repsect.
Hartman's Law of Prescriptivist Retaliation illustrated!
(The Law states that "Any article or statement about correct
grammar, punctuation, or spelling is bound to contain at least
one eror.")

Signature
Eric Sosman
esosman@acm-dot-org.invalid
Andrew Thompson - 21 Apr 2007 12:57 GMT
>>> Hi...I am new to java......
>>
[quoted text clipped - 3 lines]
>
> Hartman's Law of Prescriptivist Retaliation illustrated!
Is there a problem, occifer? ;-)

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Eric Sosman - 21 Apr 2007 19:51 GMT
>>>> Hi...I am new to java......
>> [quoted text clipped - 17 lines]
[quoted text clipped - 3 lines]
>
> Is there a problem, occifer? ;-)
Any more back-talk and you'll get a stiff sentnce.
(If you had snipped sixteen instead of seventeen lines,
this would make more sense.)

Signature
Eric Sosman
esosman@acm-dot-org.invalid
Andrew Thompson - 22 Apr 2007 02:57 GMT
...
> (If you had snipped sixteen instead of seventeen lines,
>this would make more sense.)
My apologies. I saw what you meant, the trimming was
'automagic' by my posting interface. Must take that up
with them.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
rossum - 21 Apr 2007 09:50 GMT
>Hi...I am new to java......can anyone pls. help me in reading a csv
>file using core java.
[quoted text clipped - 3 lines]
>It wud be of great help if u can provide me with sample code.
>Thanks in advance.
Start by writing a very simple short console program to open a file
and copy its contents to the screen. If you can't do that then you
need to start with a simpler question.
Once you can open a file and display its contents, then you can have a
look at parsing the CSV file itself. For myself I used a simple
state-machine to do the parsing. There are other methods available as
well.
rossum
frustratedprogrammer@gmail.com - 23 Apr 2007 00:29 GMT
> Start by writing a very simple short console program to open a file
> and copy its contents to the screen. If you can't do that then you
> need to start with a simpler question.
It has always surprised me that there are no open source
implementations for reading CSV in java. I had a look around for one
recently and I could only find some commercial offerings. I would have
thought reading CSV was quite common.
-----
f.p.
frustratedprogrammer@gmail.com
http://frustrationsofaprogrammer.blogspot.com
Martin Gregorie - 23 Apr 2007 13:00 GMT
>> Start by writing a very simple short console program to open a file
>> and copy its contents to the screen. If you can't do that then you
[quoted text clipped - 4 lines]
> recently and I could only find some commercial offerings. I would have
> thought reading CSV was quite common.
It is, but AFAIK CSV libraries are not common or standard for any language.

Signature
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
David Segall - 23 Apr 2007 14:24 GMT
>> Start by writing a very simple short console program to open a file
>> and copy its contents to the screen. If you can't do that then you
[quoted text clipped - 4 lines]
>recently and I could only find some commercial offerings. I would have
>thought reading CSV was quite common.
You should start here too <http://mindprod.com/jgloss/csv.html>
David Segall - 21 Apr 2007 13:46 GMT
>Hi...I am new to java......can anyone pls. help me in reading a csv
>file using core java.
[quoted text clipped - 3 lines]
>It wud be of great help if u can provide me with sample code.
>Thanks in advance.
Start here <http://mindprod.com/jgloss/csv.html>
Sanjay - 21 Apr 2007 13:54 GMT
> Hi...I am new to java......can anyone pls. help me in reading a csv
> file using core java.
[quoted text clipped - 3 lines]
> It wud be of great help if u can provide me with sample code.
> Thanks in advance.
If it is comma separated, open the file and read it line by line using
buffered input stream. Once you have the line, then split it using
String.split. You may want to look at second parameter called "limit" in
the overloaded method.
Lew - 21 Apr 2007 14:05 GMT
>> Hi...I am new to java......can anyone pls. help me in reading a csv
>> file using core java.
[quoted text clipped - 8 lines]
> String.split. You may want to look at second parameter called "limit" in
> the overloaded method.
That approach needs special care to deal with commas that are not separators.

Signature
Lew
Martin Gregorie - 21 Apr 2007 14:58 GMT
>> Hi...I am new to java......can anyone pls. help me in reading a csv
>> file using core java.
[quoted text clipped - 7 lines]
> buffered input stream. Once you have the line, then split it using
> String.split.
That's too simplistic. It would go wrong with something like:
42,"The answer to Life, the Universe and Everything"
which consists of two, comma separated fields.

Signature
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Sanjay - 22 Apr 2007 20:06 GMT
>>> Hi...I am new to java......can anyone pls. help me in reading a csv
>>> file using core java.
[quoted text clipped - 13 lines]
>
> which consists of two, comma separated fields.
Well, yes. You are right. However, I was just trying to give a starting
point. Besides we know nothing about his data, so it may or may not have
commas in them.
Martin Gregorie - 22 Apr 2007 21:19 GMT
> Well, yes. You are right. However, I was just trying to give a starting
> point. Besides we know nothing about his data, so it may or may not have
> commas in them.
Its not just the commas. Any non-trivial CSV implementation must be able
to deal with quoted strings which may, of course, contain quotes as well
as field separators. CSV files are both more complex and less
standardized than many people realize.
Even as a programming course exercise I'd mark down a solution that
didn't deal correctly with those factors.
And that's ignoring the bells and whistles that any proper CSV
implementation should handle, such as the ability to change the field
separator and to control the level of field quoting (quote all fields;
quote only those containing quote marks or separators; suppression of
all quoting). There's also the issue of stripping leading and trailing
spaces. Virtually all database loaders deal with CSV and all the ones
I've met have the ability to redefine the field separator.

Signature
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
shriop - 24 Apr 2007 15:06 GMT
On Apr 22, 3:19 pm, Martin Gregorie <mar...@see.sig.for.address>
wrote:
> >> Well, yes. You are right. However, I was just trying to give a starting
> > point. Besides we know nothing about his data, so it may or may not have
[quoted text clipped - 16 lines]
> spaces. Virtually all database loaders deal withCSVand all the ones
> I've met have the ability to redefine the field separator.
I don't think any of you guys have really looked around at what solid
csv implementations are out there.
http://sourceforge.net/projects/javacsv
http://sourceforge.net/projects/opencsv
http://mindprod.com/jgloss/csv.html
http://www.ricebridge.com/products/csvman.htm
http://www.csv-jdbc.com/