2015-02-23 155 views
0

我想讀取java中的bin文件。我在項目的文件夾中創建名稱爲doc的文件夾,並在doc文件夾中添加了bin文件。我想閱讀這個代碼;如何在eclipse中讀取位於java項目文件夾中的bin文件

String fileName = "10.bin"; 
byte[] data = new byte[1024]; 
int readBytes; 

try { 
    FileInputStream in = new FileInputStream(fileName); 
    while((readBytes = in.read(data)) != -1){ 

    System.out.println("read " + readBytes + "bytes, and placed them into temp array named data"); 
    } 
    in.close(); 

} catch (FileNotFoundException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

命名爲10.bin這個bin文件是doc文件夾,你可以在圖片中看到

enter image description here

我不能與此代碼訪問文件。請幫幫我。

回答

0

首先你得給文件名的路徑

File fileName = new File("your fileName path goes here"); 
FileInputStream in = new FileInputStream(fileName); 
+0

一些閱讀:http://www.java-examples.com/read-file-using-fileinputstream – SabaRish 2015-02-23 12:33:58

相關問題