file.delete()返回false,即使file.exists(),file.canRead(),file.canWrite(),file.canExecute()都返回true
我正在尝试删除文件,在写完文件后,用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(); }}
如图所示,我刷新并关闭流,但是当我尝试删除时,file.delete()
返回false。
我删除前检查,看看是否该文件存在,并且:file.exists()
,file.canRead()
,file.canWrite()
,file.canExecute()
所有返回true。在调用这些方法后,我尝试file.delete()
返回false。
有什么我做错了吗?
蓝山帝景
梵蒂冈之花
炎炎设计
相关分类