我希望能在程序运行时删除一个内部文件。当我从外部服务器下载文件时,旧的同名文件会被替换,但我无法读取它。我认为在下载新版本前需要删除旧文件。以下是我目前尝试过的示例代码:
try {
FileOutputStream fos = getApplicationContext().openFileOutput("mytext.txt", Context.MODE_PRIVATE);
fos.write(getStringFromFile(pictosFile.getAbsolutePath()).getBytes());
Log.e("mytextfile",""+getStringFromFile(pictosFile.getAbsolutePath()));
progressDialog.cancel();
fos.close();
}
catch (IOException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
这使我能够将文件保存到内部存储器中,但我不确定在写入新版本之前如何删除先前的文件。