파일에 HashMap이있는 personHashMap.ser
파일이 있습니다.파일의 새 내용 만 5 분마다 업데이트하십시오.
String file_path = ("//releasearea/ToolReleaseArea/user/personHashMap.ser");
public void createFile(Map<String, String> newContent) {
try{
File file = new File(file_path);
FileOutputStream fos=new FileOutputStream(file);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(newContent);
oos.flush();
oos.close();
fos.close();
}catch (Exception e){
System.err.println("Error in FileWrite: " + e.getMessage());
}
}
지금 내가 원하는, 프로그램이 실행되는 모든 오분 만 변경 내용으로 파일 personHashMap.ser
을 업데이트 : 여기에 내가 그것을 만드는 방법 코드입니다. 그래서 내가 전화 한 방법 :
public void updateFile(Map<String, String> newContent) {
Map<String, String> oldLdapContent = readFile();
if(!oldLdapContent.equals(ldapContent)){ // they arent the same,
// so i must update the file
}
}
그러나 지금 나는 그것을 실현할 수있는 아이디어가 없습니다.
그리고 새 콘텐츠 만 업데이트하면 성능이 향상됩니까? 아니면 전체 파일을 치료하고 새 목록을 다시 삽입해야합니까?
편집이 :
해시 맵은 즉 street=Example Street
이 포함되어 있습니다.
하지만 이제는 새로운 거리가 New Example Street
입니다. 이제 파일에서 HashMap을 업데이트해야합니다. 그래서 난 그냥
'System.err.println ("FileWrite :"+ e.getMessage()); '오류 - 스택 추적을 잃어 버리고 프로그램이 실제로 실행되지 않아야합니다. 'RuntimeException'으로 다시 던지기가 더 좋습니다. – artbristol
@artbristol : 감사합니다.하지만 먼저 코드를 실행하고 싶습니다. 그 후 오류를 잡습니다. –
@dTDesing 예,하지만 코드가 디버깅하는 동안 오류를 catch하는 것이 더 어렵습니다. – artbristol