我想打印,用於測試資產文件夾裏面兩個文件夾的內容。在資產文件夾裏面列出文件的異常
的文件夾組成:
資產
- foo.txt的
- foo1.txt
但該方案對我說,有沒有文件。
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e1) {
e1.printStackTrace();
}
for (int i = 0; i < files.length; i++) {
File file = new File(files[i]);
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
Log.e(" ", " " + scanner.next());
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
logcat的
10-06 19:38:16.328: W/System.err(12250): java.io.FileNotFoundException: /foo.txt: open failed: ENOENT (No such file or directory)
10-06 19:38:16.335: W/System.err(12250): at libcore.io.IoBridge.open(IoBridge.java:416)
10-06 19:38:16.335: W/System.err(12250): at java.io.FileInputStream.<init>(FileInputStream.java:78)
10-06 19:38:16.343: W/System.err(12250): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
10-06 19:38:16.351: W/System.err(12250): at libcore.io.Posix.open(Native Method)
10-06 19:38:16.351: W/System.err(12250): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
當然,沒有所討論對象的「絕對路徑」,因爲當它到達設備時,它不再是一個文件。 – 2014-10-06 18:12:28