該程序在終端窗口中給我一個「例外」。 prevData.txt的位置如代碼所示。我的問題是什麼?文件輸出/輸入異常
我正在使用Bluej。還有其他問題嗎?請問。
import java.io.*;
public class prevDataReset{
public static void main(String args[]){
try{
byte bWrite [] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
OutputStream os = new FileOutputStream("C:/prevData.txt");
for(int x=0; x < bWrite.length ; x++){
os.write(bWrite[x]); // writes the bytes
}
os.close();
InputStream is = new FileInputStream("C:/prevData.txt");
int size = is.available();
for(int i=0; i< size; i++){
System.out.print((double)is.read() + " ");
}
is.close();
}catch(IOException e){
System.out.print("Exception");
}
}
}
打印stacktrace而不是「Exception」...它會更有幫助。 – mre
你應該打印e.getMessage(),這可能會得心應手。我看到的第一個紅旗是windows路徑使用\而不是/。試試看。然後嘗試將prevData放置在與JavaScript文件相同的文件夾中並使其成爲相對路徑 –
而不是'System.out.print(「Exception」);',請使用'e.printStackTrace();'然後發佈跟蹤。 –