• 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);
            }
        }
    }
  • 相关阅读:
    安装dumpling
    安装binlog(pump)
    安装部署lightning
    dumping备份成csv并使用lightning恢复
    Datax学习指南(五) 进阶datax web
    【转】PgSql删除数据库报错处理
    Spring Batch (一) 理论介绍
    frp简易配置
    Spring底层核心原理解析
    cuda、torch、torchvision对应版本以及安装
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/12176672.html
Copyright © 2020-2023  润新知