Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在不更改其他属性的情况下设置属性并存储属性文件_Java_File_Properties_Io - Fatal编程技术网

Java 如何在不更改其他属性的情况下设置属性并存储属性文件

Java 如何在不更改其他属性的情况下设置属性并存储属性文件,java,file,properties,io,Java,File,Properties,Io,我有一个像这样的属性文件 #message message.acountcv= message.applipromotion= #alert alert.auto.to.manual= alert.csv.download= ..... 我想更改属性,但顺序和格式已更改 Properties tmp = new Properties() { @Override public s

我有一个像这样的属性文件

    #message
    message.acountcv=
    message.applipromotion=       
    #alert
    alert.auto.to.manual=
    alert.csv.download=
    .....

我想更改属性,但顺序和格式已更改

Properties tmp = new Properties() {
            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<Object>(super.keySet()));
            }
        };

      Properties props = new Properties();
      myfis = new FileInputStream("/home/www/data/myproperties.properties");
      props.load(myfis);
      fos = new FileOutputStream("/home/www/data/myproperties.properties");

          props.setProperty("field.target", "123456");
            tmp.putAll(props);
            tmp.store(fos, null);
      fos.close();
      fis.close();
Properties tmp=新属性(){
@凌驾
公共同步枚举密钥(){
返回Collections.enumeration(新树集(super.keySet());
}
};
Properties props=新属性();
myfis=newfileinputstream(“/home/www/data/myproperties.properties”);
道具荷载(MYFI);
fos=新文件输出流(“/home/www/data/myproperties.properties”);
props.setProperty(“field.target”、“123456”);
tmp.putAll(道具);
tmp存储(fos,空);
fos.close();
fis.close();
谁能帮我?
谢谢

那么到底是什么问题呢?我想更改属性,但是在tmp.store之后,密钥的顺序发生了变化。当您使用java.utls.properties编写属性文件时,顺序是不保证的,并且您无法控制顺序。但是,这应该不是问题,因为无论何时使用java.util.Properties读取prop文件,顺序都无关紧要。你关心订单有什么特别的原因吗?如果是这样,您应该自己使用java i/o编写文件。