使用java无法正确更新属性文件

时间:2015-01-21 13:26:45

标签: java properties fileinputstream

我有一个属性 File.In 那个文件有3个键。我想只更新密码值。在我的应用程序密码更新和路径键值。但我不想更新Path.i想要显示相同的原样。 这是我的代码:

String _dynamicpassword="Vekent";
        Properties props = new Properties();
        InputStream fileinput = SamplePropertiesFile.class.getClassLoader().getResourceAsStream("com/tecnics/properties/sample.properties");
        props.load(fileinput);
        String _username = props.getProperty("Username");
        String _path = props.getProperty("path");
        String _password = props.getProperty("password");
        System.out.println("user name  :" + _username);
        System.out.println("path  :" + _path);
        System.out.println("Password  :" + _password);

        OutputStream output = new FileOutputStream("./src/com/tecnics/properties/sample.properties");

        System.out.println("Output ref  : " +output);
        //SecurityUtil sec=new SecurityUtil();

       // sec.encrypt(_password, _dynamicpassword);
        props.setProperty("password",_dynamicpassword);
        props.store(output, null);

这是属性文件:

Username=xyz
password=abc
path=D:/Piwik

此处运行此代码后,显示的内容如下所示

Username=xyz
password=Vekent
path=D\:/Piwik

为什么它显示路径D:/Piwik.i想要显示D:/Piwik。可以请你建议我吗?

0 个答案:

没有答案
相关问题