I'm trying to read a .xlsx file from the project folder using the following code, but it always throws FileNotFoundException
. I have attached the project structure where the file is.
public static void main(String[] args) {
try {
String excelFilePath = "DataModel.xlsx";
File file = new File(excelFilePath);
FileInputStream fis = new FileInputStream(file);
} catch (Exception ex) {
System.out.print(ex);
}
}
这是我通常的处理方式:
File file = new File( javaApplication2.class.getResource( excelFilePath ).getPath() );
classLoader.getResource()解决了问题
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.