我是这样干的
private Properties proper;
private String mode;
PropertyConfigurator.configure("log.properties");
proper=new Properties();
try{
//载入配置文件
FileInputStream propis=new FileInputStream(new File("ftp.properties"));
proper.load(propis);
}
catch(FileNotFoundException fnfe){
logger.error("配置文件未找到:"+fnfe);
}
catch(IOException ioe){
logger.error("IOException:"+ioe.getMessage());
return;
}
mode=proper.getProperty("mode");
if(mode==null||mode.equals("")){
System.out.println("未指定上传或下载模式,默认为下载!");
mode="0";
}
         System.out.println(mode);

解决方案 »

  1.   

    配置文件也很简单:
    mode=0
    autoDelete=false
    dowDownLoad=172.16.1.130
    ....
      

  2.   

    你参考着修改一下你的代码试试,good luck:)
      

  3.   

    PropertyConfigurator.configure("log.properties");
    这一行可以忽略,是载入另一个配置用的。
      

  4.   

    to IceCraft(心淡情浓):
    我主要想知道怎样对property写,谢谢你帮我改改。
      

  5.   

    改成这样:
    public class Property {
    public static void main(String[] args) {
    Properties props = new Properties();
    URL url = ClassLoader.getSystemClassLoader().getResource(
    "test.properties");
    try {
    File f = new File(url.getPath());
    InputStream is = new FileInputStream(f);
    props.load(is);
    System.out.println(props.getProperty("xy"));
    System.out.println(props.getProperty("yx"));
                OutputStream out=new FileOutputStream(f);
    props.setProperty("xy","yinxu");//此处设置xy的值
    props.store(out,"mydoc");//空白内容可以写你对此文件的注释
    out.close();
    }
    catch (Exception e)
    {
    System.err.print(e);
    }
    System.out.println(props.getProperty("xy"));
    System.out.println(props.getProperty("yx"));
    }
    }
    控制台的输出效果是:
    xuyin
    yangxin
    yinxu
    yangxin
    文件内容原来是:
    xy=xuyin
    yx=yangxin
    执行后变成:
    #myDoc
    #Thu Aug 12 17:48:04 CST 2004
    yx=yangxin
    xy=yinxuxy的内容已修改,#号表示的意思是注释,指明了修改文件的时间和你要添加的注释。
      

  6.   

    还有个问题:如果我把
    OutputStream out=new FileOutputStream(f);向上移到
    InputStream is = new FileInputStream(f);下面就又不对了,请问为什么会这样?
      

  7.   

    to IceCraft(心淡情浓):
                 如果你愿意加我QQ415009052。
      

  8.   

    我想是因为你把同一个文件先打开为输出流,没有使用,然后你又把它打开为输如流,又去读取他的数据可能就不对了。
    打开为out就进行读操作,在打开is进行写操作。