2012-12-14 39 views
0

我把.bin文件放在android的資產中。我想讀它。我用這個根:在android程序中獲取.bin文件

fis = new FileInputStream("x:" + File.separator + "work"+File.separator+"game1"+File.separator+"File"+File.separator+"game1"+File.separator+"assets"+File.separator+"01.bin"); 

但它是不正確的。運行後它顯示無法找到該文件。如何獲得這個文件?

+0

您需要提供更多的信息,但一個Android應用程序在Android上運行的是Linux的,有絕對沒有 'X:' 驅動器。 「資產」是什麼意思? Eclipse項目中的'/ assets'文件夾? –

回答

1

嘗試用這樣的事情:

AssetManager assetManager = getResources().getAssets(); 
InputStream inputStream = null; 

    try { 
     inputStream = assetManager.open("foo.txt"); 
      if (inputStream != null) 
       Log.d(TAG, "It worked!"); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

有關詳細的例子來看看這個鏈接。

Android Read File From Assets

+0

感謝您的回答。但爲什麼它有錯誤null? –

+0

你在哪一點得到錯誤null? –

+0

FileOutputStream fos = new FileOutputStream(ImageUrl +「。bin」); BufferedOutputStream bos = new BufferedOutputStream(fos); DataOutputStream dos = new DataOutputStream(bos); –

1

試試這個..

AssetManager assetManager = getResources().getAssets(); 
InputStream input; 
try 
{ 
input = assetManager.open("01.bin"); 
} 
catch (IOException e) 
{ 
e.printStackTrace(); 
} 
相關問題