package HHH; import java.io.*; import static java.lang.System.out; public class OpenFile { public static void main(String[] args) { // TODO Auto-generated method stub try{ FileInputStream rf = new FileInputStream("openFile.txt"); FileOutputStream wf = new FileOutputStream("write.txt"); int n=512; byte buffer[] = new byte[n];//buffer就是个byte类型数组 while((rf.read(buffer,0,n) != -1) && (n>0))//读取输入流 { out.print(new String(buffer));//在屏幕中输出,强制转换成字符串 wf.write(buffer,0,buffer.length); } out.println(); rf.close(); wf.close(); }catch(IOException ioe){ out.println(ioe); }catch(Exception e){ out.println(e); } } }
原文地址:https://www.cnblogs.com/caiyishuai/p/9983804.html
时间: 2024-10-13 19:12:00