Search code examples
androidfiletextassetssubdirectory

Can't access file in assets subfolder


Im developing an app using Andriod Studio and I´ve got some problemns accessing my assets subfolders. When I try to access a file, say file1, in the assets root folder, like this

AssetManager assetMng = getAssets();
InputStream textoInput;
String path = "file1.txt";

    try {
        textoInput = assetMng.open(path);
        BufferedReader r = new BufferedReader(new InputStreamReader(textoInput));
        StringBuilder total = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            total.append(line);
        }
} catch (IOException e){
        lista.add("Exception: " + e.toString());
        e.printStackTrace();
    }

I get the text successfuly. But when I change "file1.txt" to "sub\file2.txt" I get an file not found execption.

Anyone has any idea what is going on? Am I missing something?

Thanks!


Solution

  • Android is linux based - use a forward slash not backslash. So, sub/file2.txt