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);
            }
        }
    }
  • 相关阅读:
    17.1.2?Replication Formats 复制格式:
    17.1.1.9 Introducing Additional Slaves to an Existing Replication Environment 引入额外的Slaves 到一个存在的复制
    17.1.1.9 Introducing Additional Slaves to an Existing Replication Environment 引入额外的Slaves 到一个存在的复制
    mysql读写分离
    mysql读写分离
    curl 返回响应头
    01_什么是Elasticsearch
    01_什么是Elasticsearch
    perl 自动发产品
    Jzoj1164求和
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/12176672.html
Copyright © 2011-2022 走看看