Properties access configuration file

import java.io.*;
import java.util.Properties;
public class PracticeUsed  {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        loadDemo();
    }
    
    public static void loadDemo() throws IOException
    {
        Properties prop = new Properties();
        FileInputStream fis = new FileInputStream("info.txt");
        
        prop.load(fis);
        prop.setProperty("wangwu","39");
        FileOutputStream fos = new FileOutputStream("info.txt");
        prop.store(fos, "haha");
//        System.out.println(prop);
        prop.list(System.out);
        fos.close();
        fis.close();
        
    }
    public static void method_1() throws IOException
    {
        BufferedReader bufr = new BufferedReader(new FileReader("info.txt"));
        String line = null;
        Properties prop = new Properties();
        
        while((line=bufr.readLine())!=null)
        {
            String[] arr = line.split("=");
            
             System.out.println(arr[0]+"...."+arr[1]);
             prop.setProperty(arr[0],arr[1]);
            
        }
        bufr.close();
        System.out.println(prop);
    }
    
}

 

Guess you like

Origin www.cnblogs.com/zxl1010/p/11653799.html