Panos Karampis
Panos Karampis

Reputation: 586

GWT access file within WebContent

I am trying to send a folder's content as String[] but I have some problem with paths. In hosted mode the following code works fine:

File dir= new File("folder-in-webcontents-dir");    
String contents=dir.list();    
return contents;

This snippet is executed in the server side implementation of an RPC call. When this project is deployed in glassfish after using logging I see that .getabsolutefilepath() returns something like c:\glassfish\glassfish\domains\domain1\CONFIG(??)\folder-in-webcontents-dir.

How can I then point to this specific folder?

Upvotes: 0

Views: 333

Answers (2)

Harish Raj
Harish Raj

Reputation: 1575

Use:

File file = new File("/folder-in-webcontents-dir");
String contents=dir.list();    
Return contents;

Upvotes: 1

Saeed Zarinfam
Saeed Zarinfam

Reputation: 10190

You can use this code on the server side (on your RPC)

String URL = getServletContext().getRealPath("/folder-in-webcontents-dir");
File dir = new File(URL);
return dir.list();

Upvotes: 2

Related Questions