JAVA从键盘输入信息,然后保存至文件text.txt中, 求指点
//从键盘输入内容至文件;BufferedReaderstdin=newBufferedReader(newInputStreamReader(System.in));/...
//从键盘输入内容至文件;
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));//读键盘输入
FileWriter fout=new FileWriter("text.txt",true);
String str="";
while((str=stdin.readLine())!="\n")
{
System.out.println(str);
fout.write(str);
}
fout.close();
//结果:显示
Exception in thread "main" java.io.FileNotFoundException: text1.txt (拒绝访问。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at java.io.FileReader.<init>(FileReader.java:58)
at test.main(test.java:14) 展开
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));//读键盘输入
FileWriter fout=new FileWriter("text.txt",true);
String str="";
while((str=stdin.readLine())!="\n")
{
System.out.println(str);
fout.write(str);
}
fout.close();
//结果:显示
Exception in thread "main" java.io.FileNotFoundException: text1.txt (拒绝访问。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at java.io.FileReader.<init>(FileReader.java:58)
at test.main(test.java:14) 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |