码迷,mamicode.com
首页 > 其他好文 > 详细

解决读写properties属性文件

时间:2015-11-20 10:28:55      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

package com.kzkj.wx.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Properties;

/**
 * 属性文件 操作工具类
 * @author wanpeng
 * */
public class FilePropertiesUtil {
    
    /**
     * 属性文件操作类
     * */
    private static Properties pro=new Properties();
    

    /**
     * robackTOken常量
     * */
    private static final String ONLYONEROBACKTOKEN="onlyOneRobackToken";
    
    /**
     * 读取RobackToken属性文件
     * @return robackToken
     * */
    public static String readPropertise(String filelocation) throws IOException{
        String robackToken=null;
        Reader in=getReader(filelocation);
        pro.load(in);
        robackToken=pro.getProperty(ONLYONEROBACKTOKEN);
        return robackToken;
    }
    
    /**
     * 获取文件字符流
     * @param 文件路径
     * @return 文件读取字符流
     * @throws FileNotFoundException 
     * */
    private static Reader getReader(String filelocation) throws FileNotFoundException{
        File file=new File(filelocation);
        BufferedReader in=new  BufferedReader(new InputStreamReader(new FileInputStream(file)));
        return in;
    }; 
    
    /**修改属性*/
    public static void modiFicationProperties(String value,String filelocation) throws IOException{
        String robackToken=value;
        Reader in=getReader(filelocation);
        FileOutputStream os=new FileOutputStream(new File(filelocation));
        pro.load(in);
        pro.setProperty(ONLYONEROBACKTOKEN, robackToken);
        pro.store(os, "test");
    }
}

 

解决读写properties属性文件

标签:

原文地址:http://www.cnblogs.com/ak23173969/p/4979815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!