<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          java解決上傳文件接口文件過大頁(yè)面崩潰

          共 888字,需瀏覽 2分鐘

           ·

          2022-03-15 09:42

          不能直接用流讀寫文件,文件太大會(huì)使內(nèi)存不足,使用緩存循環(huán)讀寫



          for (Map.Entry me : fileMap.entrySet()) {

          MultipartFile file = me.getValue();
          String originalFilename = file.getOriginalFilename();
          //新的文件名稱
          String newFileName = res + originalFilename.substring(originalFilename.lastIndexOf('.'));
          String rootPath = upPath + File.separator + dateDirs + File.separator + newFileName;
          //新文件
          File newFile = new File(rootPath);
          //判斷目標(biāo)文件所在的目錄是否存在
          if (!newFile.getParentFile().exists()) {
          //如果目標(biāo)文件所在的目錄不存在,則創(chuàng)建父目錄
          newFile.getParentFile().mkdirs();
          }
          try(
          InputStream in = file.getInputStream();
          FileOutputStream fos = new FileOutputStream(newFile);
          BufferedOutputStream bos = new BufferedOutputStream(fos);){

          int b=-1;
          byte[]buffer = new byte[1024];
          while ((b=in.read(buffer))!=-1){
          bos.write(buffer,0,b);
          }
          }catch (Exception e){
          //將內(nèi)存中的數(shù)據(jù)寫入磁盤
          }


          瀏覽 155
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  黄色视频免费播放久久 | 狠狠撸天天撸 | 成人黄片影院网站 | 天天干天天天干 | 五月激情网站 |