windows下和linux下的file.delete的表现为什么一个删除一个不删除

凝望_Ing 2014-03-03 05:47:53
	public File downloadNotice(SysNoticeFileDto sysNotice) {
// TODO Auto-generated method stub
if("无附件".equals(sysNotice.getFilename())){
return null;
}
SysFileDataDto fileDataDto = new SysFileDataDto();
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
fileDataDto = daoSysNoticeQueryDao.downloadAttachment(sysNotice.getFileid());
file = new File(sysNotice.getFilename());
if(file.exists()){
file.delete();
}
file.createNewFile();
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
if(null != fileDataDto.getFilecontent()){
bos.write(fileDataDto.getFilecontent());
}else{
bos.write("".getBytes());
}
return file;
} catch (Exception e) {
e.printStackTrace();
return file;
}



finally {
if(file.exists()){
if(file.delete()){
System.out.println("删除文件");

}else{
System.out.println("没有删除文件");
file.deleteOnExit();
}
}
if (bos != null) {
try { bos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}

代码如上,在windows系统下会输出“没有删除文件”,但是linux系统下会输出“删除文件”,我想知道为什么一个删除一个不删除,
...全文
120 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧