File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Output File Object as List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Output File Object as List" Watch "Output File Object as List" New topic

Output File Object as List

Pete Mitchell - Maverick

Joined: Sep 26, 2012
Posts: 2

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.
Corrie L Sherone

Joined: Jan 21, 2008
Posts: 19
Edit: Nevermind. I overlooked your last line.
Kemal Sokolovic

Joined: Jun 19, 2010
Posts: 825

Once you list files with the given file filter (suppose WildcardFileFilter is from, 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.

The quieter you are, the more you are able to hear.
Pete Mitchell - Maverick

Joined: Sep 26, 2012
Posts: 2
I got it working like this. Thanks for the help!

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
And welcome to the Ranch
I agree. Here's the link:
subject: Output File Object as List
It's not a secret anymore!