在我的Android应用程序中,我在使用此函数的目录中创建文件(注意它放在一个子目录中).
gsFile = new File(getCacheDir(), "test/aa.txt");
Run Code Online (Sandbox Code Playgroud)
但是,我如何现在遍历该目录中的文件?
我试过了
File dir = new File(getCacheDir(), "test/aa.txt");
for (File f : dir.listFiles()) {
}
Run Code Online (Sandbox Code Playgroud)
但它在File f上崩溃了
kal*_*pvs 10
像这样更改您的代码并尝试..
File dir = new File(getCacheDir(), "test");
if (dir.exists()) {
for (File f : dir.listFiles()) {
//perform here your operation
}
}
Run Code Online (Sandbox Code Playgroud)