我只会用Properties类读取属性文件  那要怎么写属性文件呢 
比如我想把username=123456
改写成username=aaaa用Properties类怎么做啊 ? 谢谢!

解决方案 »

  1.   

    setProperty(String key,String value)
      

  2.   

    不行啊 我用这个方法试过 根本就改不了嘛 
    我写的 properties.setProperty("password","123456");结果打开文件看password的值还是原来的
      

  3.   

    store的第二个参数不知道是啥意思  不知道应该写什么
      

  4.   

    import java.util.*;
    import java.io.*;
    public class a {
            
        /**
         * Creates a new instance of <code>a</code>.
         */
        public a() {
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws Exception{
            // TODO code application logic here
            Properties p=new Properties();
            FileInputStream in=new FileInputStream("p.properties");
            FileOutputStream out=new FileOutputStream("op.properties");
            p.load(in);
            p.setProperty("22","kkk");
           p.store(out,"hello"); 
        }
    }
      

  5.   

    第二个参数是注释的意思,生成的文件中会有如下内容:
    #hello
    #Thu Jun 07 16:00:17 CST 2007
      

  6.   

    import java.util.*;
    import java.io.*;
    public class a {
       
        public static void main(String[] args) throws Exception{
            // TODO code application logic here
            Properties p=new Properties();
            FileInputStream in=new FileInputStream("p.properties");
            byte[] b=new byte[in.available()];
            in.read(b);
            ByteArrayInputStream bin=new ByteArrayInputStream(b);
            FileOutputStream out=new FileOutputStream("p.properties");
            p.load(bin);
           p.setProperty("22","kkk");
           p.store(out,"hello"); 
        }
    }