Topic: 如何把屏幕上输入的信息写到文件? |
Print this page |
1.如何把屏幕上输入的信息写到文件? | Copy to clipboard |
Posted by: radyjx Posted on: 2005-09-06 14:57 这是我写的程序,查了很长时间,有什么问题? import java.io.*; public class GetScreen { public static void main(String[] args) throws Exception { BufferedInputStream bi = new BufferedInputStream(System.in); FileOutputStream fileOut = new FileOutputStream("e:\\radyjx\\doc\\java\\study\\a.txt"); BufferedOutputStream bo = new BufferedOutputStream(fileOut); int flag = 0; while(flag != 10) { flag = bi.read(); System.out.print((char) flag); bo.write(flag); } } } |
2.Re:如何把屏幕上输入的信息写到文件? [Re: radyjx] | Copy to clipboard |
Posted by: dengyin2000 Posted on: 2005-09-07 09:42
|
3.Re:如何把屏幕上输入的信息写到文件? [Re: radyjx] | Copy to clipboard |
Posted by: JavaandC Posted on: 2005-09-07 14:16 你這個程序應該這樣寫就沒問題了,看註釋 mport java.io.*; public class GetScreen { public static void main(String[] args) throws Exception { BufferedInputStream bi = new BufferedInputStream(System.in); FileOutputStream fileOut = new FileOutputStream("e:/a.txt"); BufferedOutputStream bo = new BufferedOutputStream(fileOut); int flag = 0; while(flag != 10) { flag = bi.read(); System.out.print((char) flag); bo.write(flag); } bo.close();//你的數據流沒有關閉,所以數據就沒有寫進去。 } } |
4.Re:如何把屏幕上输入的信息写到文件? [Re: radyjx] | Copy to clipboard |
Posted by: JavaandC Posted on: 2005-09-07 14:17 忘了,還有bi.close();也應該關閉。 |
5.Re:如何把屏幕上输入的信息写到文件? [Re: radyjx] | Copy to clipboard |
Posted by: liner09136 Posted on: 2005-09-10 14:44 呵呵,我最近也在学。学习中。。 |
6.Re:如何把屏幕上输入的信息写到文件? [Re: radyjx] | Copy to clipboard |
Posted by: CunningFox Posted on: 2005-09-22 10:04 import java.io.*; public class GetScreen{ public static void main(String[] args) throws Exception{ OutputStream os = null; InputStream is = null; try{ os = new BufferedOutputStream(new FileOutputStream("a.txt")); is = new BufferedInputStream(System.in); int i; while((i=is.read())!=10) { os.write; } }catch(Exception e){ System.out.println; }finally{ is.close(); os.close(); } } } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |