• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output File Object as List

 
Pete Mitchell - Maverick
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am passing a list of file names to another object and having problems.
The hard coded version works and looks like this. We are passing jpegFile to another object and its processed correctly with the following code.

As you can see the object receiving jpegFile expects List<string>
The above code works good. However what I really need to do is read in the file names from a directory.
That part is also working with the code below.


Is there a way to convert jpgFiles from a File object to a List, or String?
I can do:
String TestString = jpgFiles[0].toString...however I would like to convert more than 1 index at a time.
I have tried quite a few things...and keep getting Cannot convert...errors. It needs to be formatted the same as in the first code example. Can someone show me how to do this?

I also did:

And it worked good...Only problem was it only returned the filename...and I need the full path as it's returned as a File.
Thanks
 
Corrie L Sherone
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit: Nevermind. I overlooked your last line.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you list files with the given file filter (suppose WildcardFileFilter is from org.apache.commons.io.filefilter), you get array of File objects. One solution might be to initialize String array based on the length of that File array; in your case JPEG_FILES to be of size jpegFiles.length. Then you can use for loop to populate JPEG_FILES array with Strings, where each String represents path to the file by using getCanonicalPath() method of File class.
 
Pete Mitchell - Maverick
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working like this. Thanks for the help!

 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic