• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts FormFile (parsing .csv files)

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am allowing our users to upload .csv files, but was having a little trouble deciding how to parse the file content. Normally, I'd wrap the .csv file in a BufferedReader and read it line by line, but with a FormFile object, I only have an InputStream to read the file data. I'm going to add each line in the file to a List object to save to a database.

I'm not a big I/O API expert, so does someone have a clean way to read the .csv data using the Struts FormFile object?

Thanks for any help,
D
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
InputStream -> InputStreamReader -> BufferedReader
 
Daniel McDade
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Ess wrote:InputStream -> InputStreamReader -> BufferedReader



Joe, so something like the following should work? Thanks for your help.


I've been told users can also upload the data as a .txt file, but I'm thinking this should work under that scenario, too.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A CSV file *is* a text file.
 
Daniel McDade
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:A CSV file *is* a text file.



True enough. :=)
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel McDade wrote:



Do not do this. ready() does not tell you if the stream has ended, it tells you if a read call will block:

Returns:
True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.



javadoc
 
Daniel McDade
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Ess wrote:Do not do this. ready() does not tell you if the stream has ended, it tells you if a read call will block:



Joe, based on what I saw, the following would be a better approach, correct?


 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel McDade wrote:
Joe, based on what I saw, the following would be a better approach, correct?



Yes, that's how I'd do it
 
reply
    Bookmark Topic Watch Topic
  • New Topic