2012-12-14 105 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(); 
} 
相关问题