FileOutputStream的问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 02:18:47
代码如下:
Properties props = new Properties();
InputStream is = getClass().getResourceAsStream("test.properties");
try{
props.load(is);
is.close();
System.out.println(props.getProperty("test"));
props.setProperty("test", "reset");
FileOutputStream fos = new FileOutputStream("test2",true);
props.store(fos, null);
fos.write("httpL//juncsu.blogcn.com".getBytes());
fos.close();
}catch(Exception ex){
ex.printStackTrace();
}

结果是属性文件的内容可以读出来,但是无法写进去,测试中FileOutputStream直接写入也没有反应。不知道什么情况会导致这样的问题?或者有其他写Properties的方法?

网上有一些文本读写的例子

/**
* 读出1.txt中的内容,写入2.txt中
*
*/

import java.io.*;

public class readwritefile{
public static void main(string[] args){
try{

file read = new file("c:\\1.txt");
file write = new file("c:\\2.txt");

bufferedreader br = new bufferedreader(
new filereader(read));
bufferedwriter bw = new bufferedwriter(
new filewriter(write));
string temp = null;
temp = br.readline();
while(temp != null){
//写文件
bw.write(temp + "\r\n"); //只适用windows系统
//继续读文件
temp = br.readline();
}

bw.close();
br.close();

}catch(filenotfoundexception e){ //文件未找到
system.out.println (e);
}catch(ioexception e){
system.out.println (e);
}
}
}

FileOutputStream fos = new FileOutputStream("test2",true);
test2文件没有扩展名