java程序测试之字节流

package filestream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class ByteStreamTester {

    public static void main(String [] args)
    {
        FileInputStream in = null;
        FileOutputStream out = null;
        String path = "E:\\java\\";
        try
        {
            in = new FileInputStream(path+"IOFile.txt");
            out = new FileOutputStream(path+"IOFile_copy.txt");
            int c;
            while ((c=in.read())!=-1)
            {
                out.write(c);
            }
        }
        catch(FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                if(in!=null)
                    in.close();
                if(out!=null)
                    out.close();
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }
            
        }
    }
}

 

posted @ 2015-03-20 22:28  JonLi  阅读(213)  评论(0编辑  收藏  举报