我正在尝试以String[]格式发送文件夹的内容,但我在路径方面遇到了一些问题。在托管模式下,以下代码运行良好:
File dir= new File("folder-in-webcontents-dir");
String contents=dir.list();
return contents;此代码片段在RPC调用的服务器端实现中执行。在使用日志记录之后将此项目部署到glassfish中时,我看到.getabsolutefilepath()返回类似于c:\glassfish\glassfish\domains\domain1\CONFIG(??)\folder-in-webcontents-dir的内容。
我怎么才能指向这个特定的文件夹呢?
发布于 2012-12-25 04:07:17
您可以在服务器端(在RPC上)使用此代码
String URL = getServletContext().getRealPath("/folder-in-webcontents-dir");
File dir = new File(URL);
return dir.list();发布于 2012-12-25 04:00:17
使用:
File file = new File("/folder-in-webcontents-dir");
String contents=dir.list();
Return contents;https://stackoverflow.com/questions/14024673
复制相似问题