英文:
How to find files inside a folder when war file is deployed on server?
问题
我可以使用**getResourceAsStream()**函数来读取特定的文件。我已经尝试过使用相同的输入流来获取文件名,但那并没有起作用。以下是我用于此的代码:
BufferedReader rdr = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(path)));
String line;
while ((line = rdr.readLine()) != null) {
LOG.info("测试文件:" + line);
}
rdr.close();
更多信息: ZIP 文件部署在 Wildfly 服务器上。
尝试使用以下代码来获取整个路径,但它会提供错误的位置:
this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
英文:
I am able to read specific files using getResourceAsStream() function. I have tried using the same input stream for fetching file names but that did not work. This is the code that i used for that
BufferedReader rdr = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(path)));
String line;
while ((line = rdr.readLine()) != null) {
LOG.info("Testing File: " + line);
}
rdr.close();
More info : zip file is deployed on wildfly server
Tried fetching whole path with this but it gives wrong location
this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
专注分享java语言的经验与见解,让所有开发者获益!
评论