我使用FileWriter创建了一个txt-File:
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文件。 那是什么?感谢所有帮助!
答案 0 :(得分:0)
解决方法:我没有查找新文件并处理它,而是使用了
File f = new File(pathToNewFile);
然后我复制了f。