zoukankan      html  css  js  c++  java
  • Java Properties

    读取/写入:

    Properties prop = new Properties();
    String savePath = ResourceUtils.getURL("csmsystem/src/main/resources/sysconf").getPath();
    String systemConf = savePath+"systemBackup_config.properties";
    FileInputStream fis = new FileInputStream(systemConf);
    //读取键值对
    prop.load(fis);
    prop.put("backup_dir",backupSet.getContents());
    OutputStream os = new FileOutputStream(systemConf);
    //持久化到属性文件中
    prop.store(os,"Update backup_dir value");
    if(null!=fis){
       fis.close();
     }
     if(null!=os){
        os.close();
     }

    load源码:就是把文件格式化成map

    private void load0 (LineReader lr) throws IOException {
            char[] convtBuf = new char[1024];
            int limit;
            int keyLen;
            int valueStart;
            char c;
            boolean hasSep;
            boolean precedingBackslash;
     
            while ((limit = lr.readLine()) >= 0) {
                c = 0;
                keyLen = 0;
                valueStart = limit;
                hasSep = false;
     
                //System.out.println("line=<" + new String(lineBuf, 0, limit) + ">");
                precedingBackslash = false;
                while (keyLen < limit) {
                    c = lr.lineBuf[keyLen];
                    //need check if escaped.
                    if ((c == '=' ||  c == ':') && !precedingBackslash) {
                        valueStart = keyLen + 1;
                        hasSep = true;
                        break;
                    } else if ((c == ' ' || c == '	' ||  c == 'f') && !precedingBackslash) {
                        valueStart = keyLen + 1;
                        break;
                    }
                    if (c == '\') {
                        precedingBackslash = !precedingBackslash;
                    } else {
                        precedingBackslash = false;
                    }
                    keyLen++;
                }
                while (valueStart < limit) {
                    c = lr.lineBuf[valueStart];
                    if (c != ' ' && c != '	' &&  c != 'f') {
                        if (!hasSep && (c == '=' ||  c == ':')) {
                            hasSep = true;
                        } else {
                            break;
                        }
                    }
                    valueStart++;
                }
                String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);
                String value = loadConvert(lr.lineBuf, valueStart, limit - valueStart, convtBuf);
                put(key, value);
            }
        }
    }
  • 相关阅读:
    Swift中函数
    Swift 中的开关语句switch在swift中的使用
    Swift 函数新特性
    Swift 学习-多线程
    安卓学习
    ios -网络
    ios 中block
    Lua 简易调试
    iOS、Cocos2dx、Unity3D下的坐标系统简介
    Lua开发过程中遇到的一些小问题
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/12176672.html
Copyright © 2011-2022 走看看