批量讀文件為一個String(一個文件夾下的大量xml文件)
阿新 • • 發佈:2017-07-03
net family lin port title enc window blank bst String folder = "/nasapp/datamerger/xmls/ " ; File file = new File(folder); if(!file.exists()){ file.mkdir(); } File[] files = file.listFiles(); for(File f:files){ try { if (f.isFile() && f.exists() && "xml".equals(f.getName().substring(f.getName().lastIndexOf("." )+1))) { StringBuffer buffer = new StringBuffer(); String encoding = "UTF-8"; InputStreamReader read = new InputStreamReader(new FileInputStream(f), encoding); BufferedReader bufferedReader = new BufferedReader(read); String lineTxt = null ; while ((lineTxt = bufferedReader.readLine()) != null) { buffer.append(lineTxt); } read.close(); if(buffer!=null && StringUtils.isNotBlank(buffer.toString())){ String report = buffer.toString();}
來自為知筆記(Wiz)
來自為知筆記(Wiz)
批量讀文件為一個String(一個文件夾下的大量xml文件)