Windows 错误Java.io.FileNotFoundException
在我的项目中,我阅读excel文件。这个功能在本地主机上工作,但我在服务器上上传这个项目时,我得到如下错误Windows 错误Java.io.FileNotFoundException,windows,filenotfoundexception,Windows,Filenotfoundexception,在我的项目中,我阅读excel文件。这个功能在本地主机上工作,但我在服务器上上传这个项目时,我得到如下错误 java.io.FileNotFoundException: D:/Java_Question.xls (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:146) at
java.io.FileNotFoundException: D:/Java_Question.xls (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
因为您的项目在服务器上有不同的路径。 你应该像这样得到你的文件路径
String path = ServletContext.getRealPath("/FolderInYourProjectWhereExcelIsLocated");
@莱斯科弗。。我加上这个path@leskover我在上面添加了我的read excel文件代码,请检查它并告诉我在哪里添加字符串路径?我想知道如何从serverString path=ServletContext.getRealPath(“/FolderInYourProjectWhereExcelIsLocated”)实现read excel文件的代码的解决方案;我在哪里实现上述代码
String path = ServletContext.getRealPath("/FolderInYourProjectWhereExcelIsLocated");