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);
            }
        }
    }
  • 相关阅读:
    【javaSE】Exception in thread "main" java.lang.ArrayStoreException: java.lang.Integer
    property
    多继承与super
    GIL全局解释器锁
    深浅拷贝
    生成器
    迭代器
    设置ll命令
    修改Centos中的ll命令(以 K 为单位显示文件大小)
    打包解压缩命令
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/12176672.html
Copyright © 2011-2022 走看看