2

にあるファイルを読みたい

Environment.getDataDirectory()

(Androidデバイスのデータディレクトリ)しかし、私はできません。

誰でも私を助けてくれますか。

ファイルコードは次のとおりです。

File aFile = new File(Environment.getDataDirectory(), "/");
File file = new File(Environment.getExternalStorageDirectory(), "/filelist.txt");

public void Process(File aFile) {
    spc_count++;

    try {
        fos = new FileOutputStream(file,true);
        for (int i = 0; i < spc_count; i++)
            spcs += " ";
        if(aFile.isFile()){

            fos.write(aFile.getPath().getBytes());
            fos.write('|');
        }
        else if (aFile.isDirectory()) {

            File[] listOfFiles = aFile.listFiles();
            if(listOfFiles!=null) {
                for (int j = 0; j < listOfFiles.length; j++)
                    Process(listOfFiles[j]);
            } else {
                //System.out.println(spcs + " [ACCESS DENIED]");
            }
        }
        spc_count--;
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        // handle exception
    } catch (IOException e) {
        // handle exception
    }
}
4

1 に答える 1

2

これは、そのディレクトリへの読み取りアクセス権がないためです。

于 2013-09-02T14:24:22.173 に答える