• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Output File Object as List  RSS feed

 
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit: Nevermind. I overlooked your last line.
 
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!

 
Marshal
Posts: 60895
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!