首页 > 其他 > 详细

Properties存取配置文件

时间:2019-10-11 15:59:39      阅读:98      评论:0      收藏:0      [点我收藏+]
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);
    }
    
}

 

Properties存取配置文件

原文:https://www.cnblogs.com/zxl1010/p/11653799.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!