JAVA 字符流读取和写入改进 148
JAVA 字符流读取和写入改进 ,用到读写便捷类
import java.io.*; public class CopyJavaDemo { public static void main(String[] args) throws IOException { File file = new File("./src/CopyJavaDemo.java"); if(file.isFile()){ //字节流进行操作 FileReader fr = new FileReader(file); String Path = "./Copy.java"; FileWriter fw = new FileWriter(Path); // int ch; // while ((ch = isr.read()) !=-1){ // osw.write(ch); // } char[] chs = new char[1024]; int len; while ((len = fr.read(chs)) !=-1){ fw.write(chs,0,len ); } fr.close(); fw.close(); }else { System.out.println("文件不存在"); } } }