File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Output File Object as List

Pete Mitchell - Maverick
Greenhorn

Joined: Sep 26, 2012
Posts: 2
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

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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


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

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

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
And welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Output File Object as List
 
Similar Threads
renaming all files in one dir
Getting a list of images from a jar file
A question regarding saving jpgs into text files.
renaming all files in one dir
How to create a link or url dynamically.