码迷,mamicode.com
首页 > 其他好文 > 详细

FileOutputStream与FileInputStream互相转换

时间:2015-05-28 19:50:10      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

List<InstorageNoticeDto> noticeList = null;

        FileOutputStream fos = null;
        FileInputStream is = null;
        File file = new File(myfile.getOriginalFilename());
        int ch = 0;
        try
        {
            is = (FileInputStream) myfile.getInputStream();
            fos = new FileOutputStream(file);
            while ((ch = is.read()) != -1)
            {
                fos.write(ch);
            }
        } catch (IOException e1)
        {
            throw new Exception("文件导入失败,失败原因:" + e1.getMessage());
        } finally
        {
            try
            {
                fos.flush();
                fos.close();
            } catch (IOException e)
            {
                throw new Exception("文件导入失败,失败原因:" + e.getMessage());
            }
        }

 

这样通过int值把InputStream流改成OutputStream流完成,不必考虑通过字节数组的长度问题

FileOutputStream与FileInputStream互相转换

标签:

原文地址:http://www.cnblogs.com/gmq-sh/p/4536707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!