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");
}
}