在安卓程序中获取.bin文件



我把.bin文件放在安卓的资产中。我想读它。我使用这个根:

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

但这是不对的。 运行后显示找不到该文件。 如何获取此文件?

尝试这样的东西:

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();
        }

有关详细示例,请参阅此链接。

安卓从资产读取文件

试试这个。

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

最新更新