오유웅-천생자연java개발 상용 라이브러리 학습노트:속성류Properties

10138 단어
import java.util.Properties;
public class PropertiesDemo01{
    public static void main(String args[]){
        Properties pro = new Properties() ;    //  Properties 
        pro.setProperty("BJ","BeiJing") ;    //  
        pro.setProperty("TJ","TianJin") ;
        pro.setProperty("NJ","NanJing") ;    
        System.out.println("1、BJ :" + pro.getProperty("BJ")) ;
        System.out.println("2、SC :" + pro.getProperty("SC")) ;
        System.out.println("3、SC , :" + pro.getProperty("SC"," ")) ;
    }
};
import java.util.Properties;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class PropertiesDemo02{
    public static void main(String args[]){
        Properties pro = new Properties() ;    //  Properties 
        pro.setProperty("BJ","BeiJing") ;    //  
        pro.setProperty("TJ","TianJin") ;
        pro.setProperty("NJ","NanJing") ;    
        File file = new File("D:" + File.separator + "area.properteis") ;    //  
        try{
            pro.store(new FileOutputStream(file),"Area Info") ;    //  
        }catch(FileNotFoundException e){
            e.printStackTrace() ;
        }catch(IOException e){
            e.printStackTrace() ;
        }
    }
};
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class PropertiesDemo03{
    public static void main(String args[]){
        Properties pro = new Properties() ;    //  Properties 
        File file = new File("D:" + File.separator + "area.properteis") ;    //  
        try{
            pro.load(new FileInputStream(file)) ;    //  
        }catch(FileNotFoundException e){
            e.printStackTrace() ;
        }catch(IOException e){
            e.printStackTrace() ;
        }
        System.out.println("1、BJ :" + pro.getProperty("BJ")) ;
        System.out.println("2、SH :" + pro.getProperty("SH")) ;
    }
};
import java.util.Properties;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class PropertiesDemo04{
    public static void main(String args[]){
        Properties pro = new Properties() ;    //  Properties 
        pro.setProperty("BJ","BeiJing") ;    //  
        pro.setProperty("TJ","TianJin") ;
        pro.setProperty("NJ","NanJing") ;    
        File file = new File("D:" + File.separator + "area.xml") ;    //  
        try{
            pro.storeToXML(new FileOutputStream(file),"Area Info") ;    //  
        }catch(FileNotFoundException e){
            e.printStackTrace() ;
        }catch(IOException e){
            e.printStackTrace() ;
        }
    }
};
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class PropertiesDemo05{
    public static void main(String args[]){
        Properties pro = new Properties() ;    //  Properties 
        File file = new File("D:" + File.separator + "area.xml") ;    //  
        try{
            pro.loadFromXML(new FileInputStream(file)) ;    //  
        }catch(FileNotFoundException e){
            e.printStackTrace() ;
        }catch(IOException e){
            e.printStackTrace() ;
        }
        System.out.println("1、BJ :" + pro.getProperty("BJ")) ;
    }
};

좋은 웹페이지 즐겨찾기