FileOutputStream与FileInputStream互相转换


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流完成,不必考虑通过字节数组的长度问题


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM