包括外部文件我創建了一個彈簧引導應用,其讀取Excel文件用於向在前端所以基本上持久性數據的其源極被顯示的數據。我能夠從我的eclipse正確運行,但是當我創建一個彈簧引導jar並從命令行運行它失敗,因爲文件不包含在jar中。春季啓動JAR
我已經嘗試了兩種位置的src /主/資源/ src目錄/主/ web應用/ WEB-INF /外部/但在這兩種情況下,不包含這些文件。
代碼:
private static final String FILE1 = "\\src\\main\\webapp\\WEB-INF\\external\\file1.csv";
private static final String FILE2 = "\\src\\main\\webapp\\WEB-INF\\external\\file2.csv";
private static String currentDirectory = Paths.get(".").toAbsolutePath().toString();
private static String completeAbsolutePath = currentDirectory
.substring(0, currentDir.length() - 1)
.replace("\\", "\\\\");
reader = new CSVReader(new FileReader(completePath + FILE1))
錯誤:
java.io.FileNotFoundException: C:\刪除\ SRC \主\ web應用\ WEB-INF \外部\ File1.csv
有人可以幫忙嗎?
,請複製粘貼,你指的是文件 – zuckermanori
https://stackoverflow.com/questions/22886083/how-do-i-run-a-spring-boot-executable-jar-in-a代碼 - 生產環境 –
喜@zuckermanori下面是代碼:我從兩個文件(把它們當作兩個獨立的數據庫表) 私有靜態最後絃樂FILE1 =「\\ \\的src主要\\ \\ web應用WEB讀取數據-INF \\外部\\ file1.csv「; private static final String FILE2 =「\\ src \\ main \\ webapp \\ WEB-INF \\ external \\ file2.csv」;私人靜態字符串completeAbsolutePath = currentDir.substring(0,currentDir.length() - 1).replace(「\\」,「\\\\」); reader = new CSVReader(new FileReader(completePath + FILE1)) –