日期:2014-05-20 浏览次数:20701 次
import java.io.*; public class DataStreamTest { public static void main(String[] args) { File file1 = new File("e:/testff.txt"); File file2 = new File("e:/testff.txt"); FileInputStream fis = null; FileOutputStream fos = null; DataInputStream dis = null; DataOutputStream dos = null; try { fis = new FileInputStream(file1); dis = new DataInputStream(fis); int n = 0; byte[] buff = new byte[1024]; String data = ""; int i = 0; while((n=dis.read(buff))!=-1){ data += new String(buff,0,1,"iso-8859-1"); } fos = new FileOutputStream(file2); dos = new DataOutputStream(fos); dos.write(data.getBytes()); // dos.write(-1); // dos.write(-1); // dos.write(-1); // dos.write(-1); // dos.write(-1); // dos.write(-1); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if(dis!=null)dis.close(); if(fis!=null)fis.close(); if(dis!=null)dis.close(); if(dos!=null)dos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }