zoukankan      html  css  js  c++  java
  • 解决读写properties属性文件

    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");
        }
    }
  • 相关阅读:
    北京之行
    csharp进界
    医院OA系统新思考
    茗洋博客
    monkey主要参数详解
    使用python判断Android自动化的渠道包是否全部打完
    手机连接mac电脑无法使用adb命令解决方法
    Python正则表达式指南
    Mac基本命令大全
    Mac之vim普通命令使用
  • 原文地址:https://www.cnblogs.com/ak23173969/p/4979815.html
Copyright © 2011-2022 走看看