文件读写
来源:互联网 发布:百度知道问答知乎 编辑:程序博客网 时间:2024/06/07 19:29
- //从键盘输入一行文字,写入文件中
package project07;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;public class TestFileOut { public static void main(String[] args) { char c[] = new char[512]; int n,i; try { FileWriter wf = new FileWriter("D:/result.txt"); //利用InputStreamReader正确读取中文 System.out.println("请输入中文:"); InputStreamReader isr = new InputStreamReader(System.in); n = isr.read(c,0,512);//一次性读取512个字符,n表示实际读取的字符数 wf.write(c); wf.close(); System.out.println("刚刚输入的数据为:"+String.valueOf(c,0,n)); } catch (IOException e) { // TODO Auto-generated catch block System.out.println(e); } }}
阅读全文