我是这样干的
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);
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);
解决方案 »
- 用Java Socket请求网页数据,遇到301永久重定向问题
- 表达能力不好,只能笼统地说是J2SE连接数据库的问题 麻烦大家帮我解决一下 谢谢
- 如何输出数组里的元素
- 關於java中按值傳遞的疑問
- java连接mysql问题,,急急
- 各位大哥,明年毕业的小弟天要过两天就要和一家学校签约了,这家学校签约的方式非常奇怪,他们说签协议时要付500元保证金,这样即便你明
- 请帮我解决一个i18n的问题,100份相送!
- 运行问题(连接)
- Jbuilder在WIN2000SERVER下怎么不能安装呀?
- 关于字符集转换的问题,欢迎精通这方面的高手参与讨论
- JDK 1.4.2 with netbean 的问题
- 一个关于设置光标的问题
mode=0
autoDelete=false
dowDownLoad=172.16.1.130
....
这一行可以忽略,是载入另一个配置用的。
我主要想知道怎样对property写,谢谢你帮我改改。
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的内容已修改,#号表示的意思是注释,指明了修改文件的时间和你要添加的注释。
OutputStream out=new FileOutputStream(f);向上移到
InputStream is = new FileInputStream(f);下面就又不对了,请问为什么会这样?
如果你愿意加我QQ415009052。
打开为out就进行读操作,在打开is进行写操作。