2014-10-08 35 views
0

有人能告訴我我的代碼有什麼問題嗎?我得到一個錯誤,當我試圖將文件加載到一個fileInputStreamjavafx加載推箱子文件

錯誤消息:

java.io.FileNotFoundException: file:\C:\Users\zzxx\Desktop\netBean\hw3\Sokoban_draft\data\1.sok (The filename, directory name, or volume label syntax is incorrect) 
at java.io.FileInputStream.open(Native Method) 
at java.io.FileInputStream.<init>(FileInputStream.java:138) 

代碼:

String filePath = new String("file:///C:/Users/zzxx/Desktop/netBeanhw3/Sokoban_draft/data/1.sok"); 

GridRenderer gamePane = new GridRenderer(); 

File sokFile = new File(filePath); 

byte[] bytes = new byte[Long.valueOf(sokFile.length()).intValue()]; 
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); 
FileInputStream fis = new FileInputStream(sokFile); 
BufferedInputStream bis = new BufferedInputStream(fis); 
+0

你有一個包含名爲「C:」的文件夾的「file:」驅動器嗎? – immibis 2014-10-08 08:22:51

回答

0

你不需要指定文件協議。 (file:///)

請改用路徑名稱。

+0

我試過「file:data/1.sok」,但仍然不起作用 – 2014-10-08 17:11:54

+0

兄弟,我說,你不需要協議。使用「C:/Users/zzxx/Desktop/netBeanhw3/Sokoban_draft/data/1.sok」 – galovics 2014-10-08 19:46:12