标签:put output lte art 文件内容 引入 except static bsp
1 <dependency> 2 <groupId>commons-io</groupId> 3 <artifactId>commons-io</artifactId> 4 <version>2.6</version> 5 </dependency>
1 public static byte[] readZipFileToByteArray(String filePath) throws Exception { 2 File file = new File(filePath); 3 if(!file.exists()){ 4 return new byte[0]; 5 } 6 return FileUtils.readFileToByteArray(file); 7 }
1 public static void convertByteArrayToZipFile(byte[] certFile,String filePath) throws IOException{ 2 File zipFile = new File(filePath); 3 try ( 4 OutputStream out = new FileOutputStream(zipFile); 5 ){ 6 out.write(certFile); 7 out.flush(); 8 }catch (Exception e){ 9 throw new IOException(e); 10 } 11 }
1 public static String getFileContent(String zipFilePath,String innerFileName) throws IOException { 2 ZipFile zipFile = new ZipFile(zipFilePath); 3 String collect = zipFile.stream().filter(entry -> { 4 return ((ZipEntry) entry).getName().equals(innerFileName); 5 }).map(e -> { 6 7 try ( 8 InputStream inputStream = zipFile.getInputStream((ZipEntry) e); 9 ) { 10 return IOUtils.toString(inputStream, "utf-8"); 11 } catch (IOException e1) { 12 e1.printStackTrace(); 13 return ""; 14 } 15 }).collect(Collectors.joining()); 16 return collect; 17 }
标签:put output lte art 文件内容 引入 except static bsp
原文地址:https://www.cnblogs.com/dukedu/p/14025116.html