package com.io1; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; //复制 public class LianXi4 { public static void main(String[] args) { FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream("e:/java/lianxi.txt"); fos = new FileOutputStream("e:/java/test.txt"); //读 int fiss =-1; String str = ""; while((fiss = fis.read())!=-1) { str +=(char)fiss; } //写 byte[] bytes =str.getBytes(); fos.write(bytes, 0, bytes.length); System.out.println("复制完成!"); fos.flush(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { try { fos.close(); fis.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }