1 25 26 package net.yagga.util; 27 28 import java.util.*; 29 import net.yagga.util.Ut; 30 import java.io.*; 31 39 40 public class AssociativeFile extends AssociativeReader 41 { 42 public static void main(String [] argv){ 43 AssociativeFile aa=new AssociativeFile(argv[0]); 44 HashMap map=new HashMap(); 45 aa.parseAssociative(map); 46 Iterator it=map.entrySet().iterator(); 47 while(it.hasNext()){ 48 Map.Entry me=(Map.Entry)it.next(); 49 System.out.println("<"+me.getKey()+">='"+me.getValue()+"'"); 50 } 51 } 52 53 String associativeFile; 54 55 public AssociativeFile(String file) 56 { 57 init(file,false); 58 } 59 public AssociativeFile(String file, boolean autocreate) 60 { 61 init(file,autocreate); 62 } 63 64 void init(String file, boolean autocreate) 65 { 66 associativeFile=file; 67 if(autocreate){ 68 File f=new File(file); 69 if(!f.exists()){ 70 PrintWriter p=Ut.openOut(associativeFile); 71 p.close(); 72 } 73 f=null; 74 } 75 } 76 77 public boolean parseAssociative(HashMap map) 78 { 79 Reader r=new InputStreamReader(ResourceMgr.openResource(associativeFile)); 81 return super.parseAssociativeReader(map,r); 82 } 83 84 85 public void write(HashMap map){ 86 PrintWriter p=Ut.openOut(associativeFile); 87 Iterator it=map.entrySet().iterator(); 88 while(it.hasNext()){ 89 Map.Entry me=(Map.Entry)it.next(); 90 p.println(me.getKey()+"="+me.getValue()); 91 } 92 p.close(); 93 } 94 } | Popular Tags |