1 package fr.jayasoft.ivy.util; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileOutputStream ; 6 import java.io.IOException ; 7 import java.util.Properties ; 8 9 10 13 public class PropertiesFile extends Properties { 14 private File _file; 15 private String _header; 16 17 public PropertiesFile(File file, String header) { 18 _file = file; 19 _header = header; 20 if (_file.exists()) { 21 FileInputStream fis = null; 22 try { 23 fis = new FileInputStream (_file); 24 load(fis); 25 } catch (Exception ex) { 26 Message.warn("exception occured while reading properties file "+_file+": "+ex.getMessage()); 27 } 28 try { 29 if (fis != null) { 30 fis.close(); 31 } 32 } catch (IOException e) { 33 } 34 } 35 } 36 37 public void save() { 38 FileOutputStream fos = null; 39 try { 40 if (_file.getParentFile() != null && !_file.getParentFile().exists()) { 41 _file.getParentFile().mkdirs(); 42 } 43 fos = new FileOutputStream (_file); 44 store(fos, _header); 45 } catch (Exception ex) { 46 Message.warn("exception occured while writing properties file "+_file+": "+ex.getMessage()); 47 } 48 try { 49 if (fos != null) { 50 fos.close(); 51 } 52 } catch (IOException e) { 53 } 54 } 55 56 } | Popular Tags |