将键盘录入的数据,通过打印流(PrintWriter)写入本项目下的aa.txt中

来源:互联网 发布:linux 777 什么权限 编辑:程序博客网 时间:2024/05/29 13:11
import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.nio.CharBuffer;public class Work01 {@SuppressWarnings("resource")public static void main(String[] args) throws Exception {//将键盘录入的数据,通过打印流(PrintWriter)写入本项目下的aa.txt中//method01();BufferedReader br = new BufferedReader(new InputStreamReader(System.in));PrintWriter pw = new PrintWriter("aa.txt");String len;while((len=br.readLine())!=null){pw.println(len);pw.flush();}br.close();pw.close();}private static void method01() throws FileNotFoundException, IOException {InputStreamReader in = new InputStreamReader(System.in);PrintWriter pw = new PrintWriter("aa.txt");int  a;char[] ch=new char[1024];while((a=in.read(ch))!=-1){pw.println(new String(ch));pw.flush();}pw.close();in.close();}}

阅读全文
0 0