【发布时间】:2010-03-15 10:37:34
【问题描述】:
我想重命名使用 openFileOutput() 创建的上下文私有文件,但我不知道如何...
我试过了:
File file = getFileStreamPath(optionsMenuView.getPlaylistName()); // this file already exists
try {
FileOutputStream outStream = openFileOutput(newPlaylistName, Context.MODE_WORLD_READABLE); // i create a new file with the new name
outStream.close();
}
catch (FileNotFoundException e) {
Log.e(TAG, "file not found!");
e.printStackTrace();
}
catch (IOException e) {
Log.e(TAG, "IO exception");
e.printStackTrace();
}
Log.e(TAG, "rename status: " + file.renameTo(getFileStreamPath(newPlaylistName))); //it return true
此代码抛出 FileNotFoundException 但文档说“打开与此上下文的应用程序包关联的私有文件以进行写入。如果文件不存在则创建文件。”所以应该在磁盘上创建新文件。 问题:当我尝试从新重命名的文件中读取时,我得到了 FileNotFoundException!
谢谢!
【问题讨论】:
标签: android