哦, 不好意思, 是store方法

解决方案 »

  1.   

    store
    public void store(OutputStream out,
                      String comments)
               throws IOException
    Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method. The stream is written using the ISO 8859-1 character encoding. 
    Properties from the defaults table of this Properties table (if any) are not written out by this method. If the comments argument is not null, then an ASCII # character, the comments string, and a line separator are first written to the output stream. Thus, the comments can serve as an identifying comment. Next, a comment line is always written, consisting of an ASCII # character, the current date and time (as if produced by the toString method of Date for the current time), and a line separator as generated by the Writer. Then every entry in this Properties table is written out, one per line. For each entry the key string is written, then an ASCII =, then the associated element string. Each character of the key and element strings is examined to see whether it should be rendered as an escape sequence. The ASCII characters \, tab, form feed, newline, and carriage return are written as \\, \t, \f \n, and \r, respectively. Characters less than \u0020 and characters greater than \u007E are written as \uxxxx for the appropriate hexadecimal value xxxx. For the key, all space characters are written with a preceding \ character. For the element, leading space characters, but not embedded or trailing space characters, are written with a preceding \ character. The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded. After the entries have been written, the output stream is flushed. The output stream remains open after this method returns. 
    Parameters:
    out - an output stream.
    comments - a description of the property list. 
    Throws: 
    IOException - if writing this property list to the specified output stream throws an IOException. 
    ClassCastException - if this Properties object contains any keys or values that are not Strings. 
    NullPointerException - if out is null.
    Since: 
    1.2 
      

  2.   

    setProperty
    public Object setProperty(String key,
                              String value)
    Calls the Hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the Hashtable call to put. Parameters:
    key - the key to be placed into this property list.
    value - the value corresponding to key. 
    Returns:
    the previous value of the specified key in this property list, or null if it did not have one.
    Since: 
    1.2 
    See Also:
    getProperty(java.lang.String)
      

  3.   

    这样写哪里错了,怎么修改不了?public boolean uptLoginInfo(String user, String Password) throws Exception {
        try{
          Properties props = new Properties();
          InputStream is = this.getClass().getClassLoader().getResourceAsStream("resource.properties");
          props.load(is);
                
          FileOutputStream out = new FileOutputStream("resource.properties");
          
          props.setProperty("User",user);
          props.setProperty("Password",Password);
          props.store(out, this.getClass().getName());
          return true;
        }
       catch(Exception e) {
         e.printStackTrace();
         return false;
       }  }
      

  4.   

    我前几天做过类似的程序,修改添加都没问题。我把你的程序修改了一下,你试试行不行!public boolean uptLoginInfo(String user, String Password) throws Exception {
        try{
          Properties props = new Properties();
          InputStream is = this.getClass().getClassLoader().getResourceAsStream ("resource.properties");
          props.load(is);
                
          FileOutputStream out = new FileOutputStream("resource.properties");
          props.remove("User");
          props.remove("Password");
          Object userObj = props.put("User",user);
          props.store(out,(String)userObj);
          Object passObj = props.put("Password",Password);
          props.store(out,(String)passObj);
          return true;
        }
       catch(Exception e) {
         e.printStackTrace();
         return false;
       }
      }
      

  5.   

    Properties prop = null;
    File file = new File(...);
    FileInputStream fis = new FileInputStream(file);
    prop = prop.Load(fid);
    String username = prop.getProperty("user");
    String passwd = prop.getProperty("passwd");
    应该是对的。
      

  6.   

    搞定了,改成如下的:
      public boolean uptLoginInfo(String user, String Password,String login) throws Exception {
        try{
          Properties props = new Properties();
          String url = this.getClass().getClassLoader().getResource("resource.properties").toString();
          url = url.substring(6,url.length()); 
          props.load(new FileInputStream(url));
         
          props.setProperty("midaUser",user);
          props.setProperty("midaPassword",Password);
          props.setProperty("midaLogin",login);
          props.store(new FileOutputStream(url), "User Login Information");      return true;
        }
       catch(Exception e) {
         e.printStackTrace();
         return false;
       }
      }