我有两个问题。
如何使用
Export.xlsx
位于目录中的文件res/
而不是这个try ( FileInputStream fileInputStream = new FileInputStream("C:\\Users\\student3\\"+sfilename+".xlsx"))
从文件中读取数据,该文件位于存档所在的同一目录中
.jar
。
我试过什么?
第一。问。
String path = "res/"+sfilename+".xlsx";
System.out.println(getClass().getClassLoader().getResource(path).toString());
File file2 = new File(getClass().getClassLoader().getResource(path).toString());
try ( FileInputStream fileInputStream = new FileInputStream(file2))
file:/C:/Users/student/IdeaProjects/batch/out/production/batch/res/ExportBatch.xlsx
Work is finished!
java.io.FileNotFoundException: file:\C:\Users\student3\IdeaProjects\batch\out\production\batch\res\ExportBatch.xlsx (Синтаксическая ошибка в имени файла, имени папки или метке тома)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at workhere.WriterXlsx.<init>(WriterXlsx.java:20)
at workhere.Start.start(Start.java:62)
at workhere.Start.main(Start.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)