file.delete() 返回 false,即使 file.exists(), file.canRead(), file.canWrite(), file.canExecute() 都返回 true
2022-08-31 11:12:43
我试图删除一个文件,在里面写了一些东西,用.这是我用来编写的代码:FileOutputStream
private void writeContent(File file, String fileContent) {
FileOutputStream to;
try {
to = new FileOutputStream(file);
to.write(fileContent.getBytes());
to.flush();
to.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
如您所见,我刷新并关闭了流,但是当我尝试删除时,返回 false。file.delete()
我在删除之前检查了该文件是否存在,并且:,都返回true。就在调用这些方法之后,我尝试返回 false。file.exists()
file.canRead()
file.canWrite()
file.canExecute()
file.delete()
我做错了什么吗?