• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Reading csv file.

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am reading one csv file, but my programs seems not working properly.
My file contents are as follows:

Rahul B||Sam C||John
J || Kim K || RAH
P


My progarms is as follows:

I am getting output as which is wrong:

Token:Rahul B
Token:Sam C
Token:John
Token: J
Token: Kim K
Token: RAH
Token: P

I expect output as:

Token:Rahul B
Token:Sam C
Token:John J
Token: Kim K
Token: RAH P

Can anybody help? to solve out the problem.

Rahul.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, why does your csv use pipes as a delimiter and the tokenizer a comma ?

The reason why it does output John and J as two separate tokes is because they appear in two different lines.

When the tokenizer splits the line that contains, there is no J, this comes in the next loop cycle.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Do you mean that always the first comma separated string is always the continuation of the previous line ?

If you assume that , then little logic code will do the trick.


 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry it's my typo mistake .....I replaced comma with ||
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,
I agree on the Sebastian ..that I read line by line that's why I am getting the output, but I want output as

Token:Rahul B
Token:Sam C
Token:John J
Token: Kim K
Token: RAH P

Is there any open source libarary you are aware of?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why an open source lib ? For what...

Just bring your csv into a format that your code can work with and you are good to go .
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there any open source libarary you are aware of?



Opensource library are not available to correct human error programs.
 
Marshal
Posts: 22449
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only easiest way to solve this is by pasting all lines together first, then use a StringTokenizer (or String.split).
reply
    Bookmark Topic Watch Topic
  • New Topic