Actually, i just want to retrieve certain header field from the Comma Separated file. i can read all the Comma Separated file and i got all the data but i just want some of it only. ,how can i do so?
What do you mean by Headers? CSV is a plain text file with comma separated values.
If you are talking about the first row of data, you already got the data with you. Or am I misunderstanding your question?
i can read all the Comma Separated file and i got all the data
and then
"Index,Code,Date,Time,Change,List" and i only want to retrieve the data for Index, Code and Date only.
What is the problem then?
In pseudo code
1) Open a stream to the file
2) Read one line of data
3) Ignore/Drop all unwanted data (Check out StringTokenizer class or String#split methods or even RegularExpressions though I feel regex would be an overkill in this scenario)
4) Process the filtered data
n jay
Greenhorn
Joined: Dec 29, 2009
Posts: 28
posted
0
p.s: thanks and if possible can you let me know ASAP if you can.
not being rude but if you think other way around, pardon me.
What i meant was that if you could tell me the way to do it (Explaination),,,not asking you the
code of it.More over, i did mention if you can.
but if you think the former or later...Im sorry because i never know that telling your situation is a wrong doing..
What gave you the impression I found your post rude? Your ASAP word attracted the link which I provided. The explanation is in the link.
I have already provided the explanation in my previous post. As for ready made code, we very much discourage it here, especially on the Beginners forum. Best way to learn is code yourself. That is the reason I provided you with the pseudo code
n jay
Greenhorn
Joined: Dec 29, 2009
Posts: 28
posted
0
Mr.Maneesh :Anyway,,if it is my fault..I am sorry,Mr.Maneesh.
Thanks for the pseudo code(eventhough I don't get it right but will try my best..;))
Christophe Verr : I dont but you all dont like that kind of answer right?? so i will try to understand
Is it possible to indicate which column i want using string tokenzier?
No. You have to go through each element via nextElement or nextToken. Instead you could use String#split which returns an array. This would be easier to access each element by its index.
n jay
Greenhorn
Joined: Dec 29, 2009
Posts: 28
posted
0
hye.
instead of using that method i used scanner and i get the column that i want.
But the problem, is it does not print the value of the specific column.
i think i miss something in the code..thanks guys for the helpful reply.
i learn a lot.
netra jay wrote:
i think i miss something in the code..
You think correct.
String strar []=i.split(";");
Shouldnt that be a comma (,) instead of a semicolon (;) ?
n jay
Greenhorn
Joined: Dec 29, 2009
Posts: 28
posted
0
thanks..
Shouldnt that be a comma (,) instead of a semicolon (;) ?
if i put comma i get all the column which i dont want(Note:there are no value of the column to).but when i put semicolon i get the specific column that i want.But, the value for the column is missing?
You told us that a line looks like "Index,Code,Date,Time,Change,List". So, you split it with ",". If you use ";" and your data is not delimited with ";", you'll get nothing.
n jay
Greenhorn
Joined: Dec 29, 2009
Posts: 28
posted
0
what if the delimiters is semicolon instead of comma like