Search code examples
androidbin

Obtain the .bin file in android program


I put the .bin file in assets of android. I want to read it. I use this root:

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

but it is not right. After run it shows can not find the file. How to get this file?


Solution

  • Try with something like this :

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

    For detailed example see this link.

    Android Read File From Assets