2015-01-15 201 views
1

在使用Andriod Studio开发应用程序时,我有一些问题访问我的资产子文件夹。 当我试图访问一个文件,说文件1,在资产根文件夹,这样无法访问资产子文件夹中的文件

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

我得到的文本successfuly。但是当我将“file1.txt”更改为“sub \ file2.txt”时,我得到一个未找到执行文件的文件。

任何人有任何想法是怎么回事?我错过了什么吗?

谢谢!

回答

1

Android是基于Linux的 - 使用正斜杠而不是反斜杠。所以,sub/file2.txt

相关问题