How to read file that is inside .apk?

1

I'm having a small problem developing an app. I need to read the information from a file that is inside the .apk of my app, that is. This file you need to read is inside my app and not outside it.

This file is inside the same package where the java class is trying to read it, but every time I execute it, it happens:

  

exception   Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

I'm trying to get the file like this:

FileInputStream fileInputStream = new FileInputStream("teste.js");

The error is taking this line. Anyone know how I can solve this? How to get the file path correctly?

Thank you.

    
asked by anonymous 04.10.2015 / 23:38

1 answer

1

Hello!

You should put it in the Assets folder!

Here is an example of how to load the file:

 /**
 * Carrega um arquivo txt 
 */
private void load(){
      try {
         final InputStream inputStream = getAssets().open("dados.txt");
         final InputStreamReader inputreader = new InputStreamReader(inputStream); 
            BufferedReader buffreader = new BufferedReader(inputreader); 
            final List<String> itens = new ArrayList<String>(0);
            String line = "";
                while ((line = buffreader.readLine()) != null){

                    itens.add(item);
                }

    } catch (IOException e) {
        e.printStackTrace();
    }
 }
    
05.10.2015 / 20:10