zoukankan      html  css  js  c++  java
  • 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流完成,不必考虑通过字节数组的长度问题

  • 相关阅读:
    os模块
    sys模块
    psutil模块
    subprocess模块
    time模块
    argparse模块
    tcp端口扫描(python多线程)
    基于http的软件仓库
    SRE思想
    redis哨兵模式
  • 原文地址:https://www.cnblogs.com/gmq-sh/p/4536707.html
Copyright © 2011-2022 走看看