想咨询一下关于FileOutputStream的问题,麻烦大佬帮忙看看~

代码如下:
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的方法?

函数式编程
浏览 181回答 2
2回答

慕桂英3389331

/*** 读出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文件没有扩展名
打开App,查看更多内容
随时随地看视频慕课网APP