Java Can';在WildFly REST应用程序中找不到文件

Java Can';在WildFly REST应用程序中找不到文件,java,rest,path,jax-rs,wildfly,Java,Rest,Path,Jax Rs,Wildfly,file.getAbsolutePath()方法返回以下内容: @Path("/other") public class Testclass { @GET @Path("/filepath") @Produces("text/html") public FileInputStream login() { File file = new File("standalone/deployments/domaci8.war/login.html");

file.getAbsolutePath()方法返回以下内容:

@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;
       }
   }
}
login.html文件位于以下位置:

C:\Program Files (x86)\wildfly-10.1.0\bin\standalone\deployments\domaci8.war\login.html
File File=new文件(“standalone/deployments/domaci8.war/login.html”)
只是创建一个
文件
对象,该文件的路径相对于JVM进程启动的文件夹

由于您已使用
standalone.bat从
C:\Program Files(x86)\WildFly-10.1.0\bin
启动了WildFly服务器,因此
file.getAbsolutePath()
返回
C:\Program Files(x86)\WildFly-10.1.0\bin\standalone\deployments\domaci8.war\login.html


如果
login.html
与rest服务在同一个应用程序中,请检查此答案。

file.getParent()
将在我的问题中返回
null
,因此我找到的唯一解决方案是创建一个文件
新文件(“”
,然后创建
字符串路径=file.getAbsolouthPath()
,使用
path=path.substring(0,path.indexOf(“\\bin”))
修剪字符串,然后您需要连接
path+=“\\standalone\\deployments\\domaci8.war\\login.html\\”
,它就是这样工作的。谢谢你的帮助。这条线终于解决了我的问题
C:\Program Files (x86)\wildfly-10.1.0\standalone\deployments\domaci8.war\login.html