@Path("/other")
public class Testclass {
@GET
@Path("/filepath")
@Produces("text/html")
public FileInputStream login() {
File file = new File("standalone/deployments/domaci8.war/login.html");
try {
return new FileInputStream(file.getAbsolutePath());
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
}
file.getAbsolutePath() 方法返回:
C:\Program Files (x86)\wildfly-10.1.0\bin\standalone\deployments\domaci8.war\login.html
login.html 文件位于此处:
C:\Program Files (x86)\wildfly-10.1.0\standalone\deployments\domaci8.war\login.html
最佳答案
File file = new File("standalone/deployments/domaci8.war/login.html");
只是创建一个 File
对象和文件的路径相对于JVM进程启动的文件夹。
由于您已使用 standalone.bat
从 C:\Program Files (x86)\wildfly-10.1.0\bin
启动 WildFly 服务器,这就是 code>file.getAbsolutePath()
返回C:\Program Files (x86)\wildfly-10.1.0\bin\standalone\deployments\domaci8.war\login.html
如果 login.html
与其余服务位于同一应用程序中,请检查 https://stackoverflow.com/a/1768290/916225这个答案。
关于java - 无法在 WildFly REST 应用程序中找到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50446256/