A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

15536889258

中级黑马

  • 黑马币:-79

  • 帖子:133

  • 精华:0

本帖最后由 15536889258 于 2015-10-30 14:51 编辑

import java.io.*;
public class Test6
{
        public static void main(String[] args)
        {

                BufferedInputStream bufis = null;
                BufferedOutputStream bufos = null;

                try
                {
                        bufis = new BufferedInputStream(new FileInputStream(
                                        "c:\\1.jpg"));
                        bufos = new BufferedOutputStream(new FileOutputStream(
                                        "c:\\2.jpg"));

                        int byt = 0;
                        while ((byt = bufis.read()) != -1)
                        {
                                bufos.write(byt);
                        }
                }
                catch (IOException e)
                {
                        throw new RuntimeException("拷贝失败");
                }
                finally
                {
                        try
                        {
                                if (bufis != null)
                                        bufis.close();
                        } catch (IOException e)
                        {
                                throw new RuntimeException("读取关闭失败");
                        }
                        try
                        {
                                if (bufos != null)
                                        bufos.close();
                        }
                        catch (IOException e)
                        {
                                throw new RuntimeException("写入关闭失败");
                        }
                }
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马