我需要檢查給定的二進制文件是否具有寫入權限。文件類API有一個bug並且在JDK7中修復了,但是我不能只升級它。爲什麼打開FileOutputStream到二進制文件會破壞它?
這裏是鏈接到bug:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6203387
當我打開它會損壞二進制文件和資源管理器顯示其大小爲零而無法啓動它一個FileOutputStream。這是代碼片段。
OS:Win7的
請幫助我理解爲什麼剛剛打開的輸出流(不寫任何東西)破壞二進制文件。有沒有解決這個問題的方法?
這裏是代碼片段:
private boolean hasWriteAccess(File file) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
} catch (Exception e) {
e.printStackTrace();
if(fos != null) {
try {
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
return false;
}
return true;
}
啊哈......非常感謝。 – user1132809