从键盘上读入任意数量的字符,写入到文件c:\\t.txt中的程序代码如下:
import java.io.*;
public class Ex_RW2
{ public static void main(String[] s) throws Exception
{ Reader kr=new InputStreamReader(System.in);
FileWriter fw=new FileWriter("c:\\t.txt");
int c;
while( (c=kr.read() )!=-1)
fw.write(c);
fw.flush();
fw.close();
}
}
运行以后,输入的字符没有写入到 c:\\t.txt中,而且t.txt中原来的数据一经运行都全部清除掉了,是怎么回事啊?
import java.io.*;
public class Ex_RW2
{ public static void main(String[] s) throws Exception
{ Reader kr=new InputStreamReader(System.in);
FileWriter fw=new FileWriter("c:\\t.txt");
int c;
while( (c=kr.read() )!=-1)
fw.write(c);
fw.flush();
fw.close();
}
}
运行以后,输入的字符没有写入到 c:\\t.txt中,而且t.txt中原来的数据一经运行都全部清除掉了,是怎么回事啊?
解决方案 »
- 求多线程在编程上应用的实例
- 一道面试题
- 严重问题:http协议上传文件,使用了jspSmartUpload这个包不行,可能是网速限制了,急求解决办法!
- [300分]List和ArrayList分别怎样用,有什么区别,map和HashMap分别怎样用,有什么区别!?给个例子说明一下!!!!
- 请教关于jdbc Statement 的问题?
- applet从服务器硬盘读数字(dat),怎样做到applet一次载入不动态随文件改变而改变?(换个问发)
- 简单的java问题!给大家送分来了!
- 31号考SCJP...大送分了!!!
- 请教高手:如何读取数据库中的image对象,并在页面上显示出来?
- netty java.lang.IndexOutOfBoundsException: readerIndex(16) + length(12) exceeds
- invoke传参问题
- 一个小程序..别人问.没空写..大虾们热下身吧.解决即结贴
楼主【syueo】截止到2008-07-10 09:15:07的历史汇总数据(不包括此帖):
发帖的总数量:11 发帖的总分数:220 每贴平均分数:20
回帖的总数量:23 得分贴总数量:3 回帖的得分率:13%
结贴的总数量:3 结贴的总分数:60
无满意结贴数:0 无满意结贴分:0
未结的帖子数:8 未结的总分数:160
结贴的百分比:27.27 % 结分的百分比:27.27 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主该结一些帖子了
去了测试下??~~
Reader kr=new InputStreamReader(System.in);
FileWriter fw=new FileWriter("c:\\t.txt");
int c;
while( (c=kr.read() )!=-1){
System.out.println(c);
fw.write(c);
fw.flush();
}
fw.close();
import java.io.*;
public class Ex_RW2
{ public static void main(String[] s) throws Exception
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new FileWriter("d:\\t.txt",true));
String content = br.readLine();
while(content!=null){
if("exit".equals(content)){
System.out.println("程序退出");
break;
}
else{
bw.write(content);
bw.newLine();
bw.flush();
}
content = br.readLine();
}
br.close();
bw.close();
}
}