資料寫入檔案

  /**
   * 產檔
   * @param filePathLocal 路徑
   * @param fileName 檔名
   * @param str內容
   * @throws IOException
   */
  public void mkFile(String filePathLocal, String fileName, String str) throws IOException {

    File file = new File(filePathLocal);
    if (!file.isDirectory()) {
      file.mkdirs();
     //資料夾權限
      file.setReadable(true, false);
      file.setExecutable(true, false);
      file.setWritable(true, false);
    }

    Path localFile = Paths.get(filePathLocal, fileName);
    BufferedWriter writer = Files.newBufferedWriter(localFile, StandardCharsets.UTF_8);
    writer.write(xml);
    writer.close();
  }

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

將多個檔案壓縮到一個檔

  /**
   * 壓縮檔案
   * @param filePathList 檔案列表
   * @param zipDest 壓縮檔資料夾
   * @return 壓縮檔路徑
   * @throws IOException
   */
public String batchDownLoadFile(List<String> filePathList, String zipDest) throws IOException {

    File zipFile = new File(zipDest, System.nanoTime() + ".zip");

    FileOutputStream fos = new FileOutputStream(zipFile);
    ZipOutputStream zos = new ZipOutputStream(fos);
    FileInputStream fis = null;
    
    Set<String> filePathSet = new HashSet<>(filePathList);
    
    try {
      for(String filePath: filePathSet) {
        fis = new FileInputStream(filePath);
        File file = new File(filePath);
        
        zos.putNextEntry(new ZipEntry(file.getName()));
      
        int tmp = 0;
        while((tmp = fis.read()) != -1) {
          zos.write(tmp);
        }
        zos.flush();
        fis.close();
        zos.closeEntry();
      } 
    }finally {
      zos.close();
      fos.close();
    }

    return zipFile.getPath();
  }

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

Q: 使用Image getInstance(final URL url)報錯 java.io.IOException: XXXXXXXX is not a recognized imageformat.

A: 確認圖檔是否為可使用格式:gif jpeg png

    /**
     * Gets an instance of an Image.
     *
     * @param filename
     *            a filename

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

  @GetMapping(value = { "/out" }, produces = MediaType.TEXT_HTML_VALUE)
  public String outIndex(Model model) {

    model.addAttribute("status", action.dataMap());
    return "/out";
  }

 

<select class="sml" name="action">

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

 @Autowired private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

 public void batchUpdate(List<User> list) {

    if(CollectionUtils.isNotEmpty(list)) {
          String sql = "INSERT INTO USER (NAME, TEL, ADDR) VALUES( :name, :tel, :addr)";
      SqlParameterSource[] batchArgs = SqlParameterSourceUtils.createBatch(list.toArray());
      nameJdbcTemplateOracle.batchUpdate(sql, batchArgs);   
    }
    
  }



@lombok.Data
public class SupStoreInfo{
  private String name;
    
  private String tel;

  private String addr;
}

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

XML過濾非法符號

String xml = "<?xml  version="1.0" encoding="big5"?><doc><PickFileID>123456</PickFileID></doc>"
xml.replaceAll("[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]", "")

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

JS OBJECT LOOP

MAP:

for (const [key, value] of prodObjMap) {
  console.log(key, value)
}

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()