• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get filename while reading csv file  RSS feed

 
S Roberts
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to read values from csv files, and order them in a table (console output). How can i output all files in a folder and read all content in this files, and get filename while reading files with the content in it. I have so far only this, but i can't became the filename in right way, i become only the last filename and not the content of this file.

This is what i become (i get only that filename, wich is at the end of the folder),



but i need all filenames in this folder with corresponding content, like:




can you please give me some suggestions in wich way to go
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First advice, as always for people writing their own CSV parser: don't. Head over to http://www.coderanch.com/how-to/java/AccessingFileFormats and use one of the existing libraries. That will future-proof you for when the files makes use of all the CSV features not implemented here.

Is there some code missing? It doesn't look like this would compile. For example, where is "files" declared?
 
S Roberts
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for supporting,


this is the head and the object class

 
S Roberts
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i made some changes, but can't get what i need:



i get only the last one file name in the folder, but not all other, how can i fix this?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I don't understand is the use of the "files" string. You assign something to it for all files, but then it's immediately overwritten during the next iteration of the loop. And since you say that only the very last file is considered, I think there is a strong correlation there :-)

you should probably roll the loop in lines 10-33 into the following loop, following line 38.
 
S Roberts
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i replace it


and can get all files, thank you. But to get the file names with the content of each file successively, should i use loop? I become only one content of first file and other filenames wothout content.
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if you want to process a set of files all in the same way, you should have a loop inside which you process one file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!