package com.hanqi.io; import java.io.*; public class IoDemo { public static void main(String[] args) { try { File file=new File("d:/testRW.txt"); if(!file.exists()) { file.createNewFile(); } FileReader fr = new FileReader(file); String str=""; char[] a=new char[1024]; int i=0; while((i=fr.read(a))>0) { str+=new String(a,0,i); } fr.close(); System.out.println("d:/testRW.txt"); System.out.println(str); File file2=new File("d:/iodemo.txt"); if(!file2.exists()) { file2.createNewFile(); } FileWriter fw=new FileWriter(file2); fw.write(str); fw.close(); FileReader fr2 = new FileReader(file2); String str2=""; char[] a2=new char[1024]; int j=0; while((j=fr2.read(a2))>0) { str2+=new String(a2,0,j); } fr2.close(); System.out.println("d:/iodemo.txt"); System.out.println(str2); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } }