Properties類文件的的操作

public class PropertiesTester {
	
	public static void main (String[] args){
		
		Properties p = new Properties();
		
	    BufferedReader in = null;
	    BufferedWriter out = null;
	    
	    try{
	    	in = new BufferedReader(new InputStreamReader(PropertiesTester.class.getResourceAsStream("test.properties")));
	    	p.load(in);
	    	p.setProperty("married", "未婚");
	    	
	    	out = new BufferedWriter(new FileWriter("D:\\Workplace\\Java_pro\\c10\\src\\com\\easyjava\\minepro\\test.properties"));
	    	p.store(out, null);
	    	
	    }catch (IOException e){
	    	e.printStackTrace();
	    }finally {
	    	if (in != null){
	    		try{
	    			in.close();
	    			out.close();
	    		}catch (IOException e){
	    			e.printStackTrace();
	    		}
	    	}
	    }
	    StringBuffer tempSb = new StringBuffer();
	    Process q = null;
		try {
			q = Runtime.getRuntime().exec(
			  "native2ascii -reverse  D:\\Workplace\\Java_pro\\c10\\src\\com\\easyjava\\minepro\\test.properties");
		} catch (IOException e) {
			e.printStackTrace();
		}
	    InputStreamReader child_in = new InputStreamReader(q.getInputStream());
	    int c;
	    try {
			while ((c = child_in.read()) != -1) {
			 tempSb.append((char) c);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	 System.out.println(tempSb);
	
	}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章