0
創建創建一個TXT的文件,FileWriter的文件:安卓:listFiles()沒有找到FileWriter的
try
{
fw = new FileWriter(filePath);
fw.write("Name: " + title);
fw.write("Publisher: " + publisher + System.getProperty("line.separator"));
fw.write("Author: " + author + System.getProperty("line.separator"));
fw.write("Book Version: " + version + System.getProperty("line.separator"));
fw.write("URL: " + url + System.getProperty("line.separator"));
fw.write("ThumbMD5: " + thumbMD5 + System.getProperty("line.separator"));
fw.write("FileMD5: " + fileMD5 + System.getProperty("line.separator"));
fw.write("Book Area Code: " + areaCode + System.getProperty("line.separator"));
fw.write("Type: " + type + System.getProperty("line.separator"));
fw.flush();
fw.close();
}
catch (IOException e) {
Log.e(TAG, "saveTxt: Couldn't create File: " + e.getMessage());
}
finally {
if (fw != null)
try { fw.close(); } catch (IOException e) { e.printStackTrace(); }
}
該文件被正確地創建,用正確的內容。當我使用Windows PC連接智能手機時,我可以打開文件。
但是當我嘗試
File dirTxt = new File(Helper.getExternalStorageDirectory() + Helper.getFileCache());
File[] txts = dirTxt.listFiles();
for (File txt : txts) {
Log.e(TAG, txt.getName());
}
該目錄中的所有文件被發現,但我的新的txt文件。 這是怎麼回事?所有幫助表示讚賞!