aspose file tools*
The moose likes JSF and the fly likes How to access folder 'resources/images' programmatically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to access folder Watch "How to access folder New topic
Author

How to access folder 'resources/images' programmatically?

Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

I have folder with many images at /myProjectRoot/resources/images/

How to access this folder in managed bean so that I am able to get names of all files(images) from it?

Thank you!


True person is moral, false is right!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

If this is an absolute filesystem path, create a java.io.File object from its value and use the File list() method.

If this is a resource within the WAR. you may may find this to be a harder task. As far as I can determine, you would have to use the getRealPath() method to contruct a File from that resource path, then list() it. However, that will only work on exploded WARs - it's not "write once, run anywhere". For cases like that, it's often easier to just keep a file in the WAR with the list of image names in it and read that as a stream resource.


Customer surveys are for companies who didn't pay proper attention to begin with.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello Tim!

I am glad to inform you that I coped with this task.
I keep my plain file where I list names of 50 images in separate folder called domain2/lib/JavaHelp/other where I also keep all uploaded photos.
It is outside my deployed project.
domain2/lib/JavaHelp/other is virtual directory which I registered on glassfish very easily as described at http://www.marceble.com/2009/07/virtual-directories-in-glassfish/
Then I read data from url by this piece of code:

Isn't it great approach?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Volodymyr Levytskyi wrote:Hello Tim!

I am glad to inform you that I coped with this task.
I keep my plain file where I list names of 50 images in separate folder called domain2/lib/JavaHelp/other where I also keep all uploaded photos.
It is outside my deployed project.
domain2/lib/JavaHelp/other is virtual directory which I registered on glassfish very easily as described at http://www.marceble.com/2009/07/virtual-directories-in-glassfish/
Then I read data from url by this piece of code:

Isn't it great approach?


I don't know. Can it throw an IOException? If so, your close may get bypassed and you could leak resources.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

Maybe the idea with virtual directories is cool and it works for me, but I finally stopped on env-entry because if path to file changes I would have to modify class itself in case of virtual directories, but with env-entry I need to modify web.xml only which I hope is less complicated.

Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access folder 'resources/images' programmatically?