File file = new File(Game.class.getResource("Tiles.txt").getFile())
從我的資源文件夾獲取txt文件後沒有找到文件,它工作正常時,IDE內部,而是建立一個罐子時和運行在環境之外它拋出文件沒有發現錯誤(我看到通過CMD運行)。
我用類似的方法來獲取所有我的圖片和雪碧表:
BufferedImage loadedImage = ImageIO.read(Game.class.getResourceAsStream("EG.png"));
他們如何在導入文件不同,爲什麼我的道路不正確的?
錯誤CMD給出: http://imgur.com/a/1SC1L
C:\Users\Taka\Desktop>java -jar ProjectC-Revamped.jar
java.io.FileNotFoundException: file:\C:\Users\Taka\Desktop\ProjectC-Revamped.jar!\Tiles.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Tiles.<init>(Tiles.java:16)
at Game.<init>(Game.java:91)
at Game.main(Game.java:192)
java.io.FileNotFoundException: file:\C:\Users\Taka\Desktop\ProjectC-Revamped.jar!\Maps\Map.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Map.<init>(Map.java:20)
at Game.<init>(Game.java:94)
at Game.main(Game.java:192)
是不工作的文件,實際上包含在.jar文件中? – TmTron
@TmTron我用winrar打開了jar,發現文本文件都在那裏 – Taka
嘗試用try catch來包圍失敗的調用併發布錯誤消息。 – TmTron