Java – 在保存到Linux属性文件时,单斜杠被转换为双斜杠。

huangapple 未分类评论51阅读模式
英文:

Java - Single Slash getting converted to Double Slash when saving in Linux Properties file

问题

我正在使用PropertiesConfiguration类来更新文件中的属性。我尝试过commons-configuration的1.9和1.10版本。我就是想不明白,出了什么问题,

**请看下面的代码示例-**

    PropertiesConfiguration conf = null;
    try {
        System.out.println("在" + filePath + "中进行更新");
        conf = new PropertiesConfiguration(filePath);
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(0);
    }
    System.out.println("将要更新的密码是" + pass);
    conf.setProperty(parName, pass);
    try {
        conf.save();
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

在Windows操作系统中,当我尝试在Eclipse中运行时,一切正常,但是当我必须在Linux操作系统中部署我的JAR文件时,在属性文件中,我总是看到两个'\',而不是一个'\'。

密码中包含'\' - `XytxvyijkZ5p+DYwn4M07EWIiGXWEk9/cnQCbQiKFOYoU8LHjg0MpxaS/GYA\n2FOASlP4Yb2ekWOD8nFmRivSBA==\n`

在属性文件中得到更新为 - `XytxvyijkZ5p+DYwn4M07EWIiGXWEk9/cnQCbQiKFOYoU8LHjg0MpxaS/GYA\\\\n2FOASlP4Yb2ekWOD8nFmRivSBA==\\\\n`
英文:

I'm using PropertiesConfiguration class to update the properties in the file. I've tried both 1.9 and 1.10 versions of commons-configuration. I just can't figure out, what is wrong with it,

Please have a look at below code-

PropertiesConfiguration conf = null;
    try {
        System.out.println("Updating in " + filePath);
        conf = new PropertiesConfiguration(filePath);
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(0);
    }
    System.out.println("Password going to be updated is " + pass);
    conf.setProperty(parName, pass);
    try {
        conf.save();
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

In windows OS, when I tried with Eclipse it's working fine but as I've to deploy my jar in Linux OS, and there in the properties file, I always see two '' instead of one '' in my properties file.

Password having '' - XytxvyijkZ5p+DYwn4M07EWIiGXWEk9/cnQCbQiKFOYoU8LHjg0MpxaS/GYA\n2FOASlP4Yb2ekWOD8nFmRivSBA==\n

Getting updated in Properties file as - XytxvyijkZ5p+DYwn4M07EWIiGXWEk9/cnQCbQiKFOYoU8LHjg0MpxaS/GYA\\\\n2FOASlP4Yb2ekWOD8nFmRivSBA==\\\\n

huangapple
  • 本文由 发表于 2020年5月19日 17:23:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/61887593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定