From fec6195e98cc163d3b96bd632f24c1f3e5b4b8c1 Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Sun, 29 Dec 2019 23:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=86=99=E5=85=A5=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 文件路径列表写入文件 --- .../java/com/frank/ffmpeg/util/FileUtil.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java index bd1fdf7..037fa3f 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java @@ -159,4 +159,50 @@ public class FileUtil { return filePath.substring(filePath.lastIndexOf("/") + 1); } + public static String createListFile(String listPath, String[] fileArray) { + if ((TextUtils.isEmpty(listPath) || fileArray == null || fileArray.length == 0)) { + return null; + } + FileOutputStream outputStream = null; + try { + File listFile = new File(listPath); + if (!listFile.getParentFile().exists()) { + if (!listFile.mkdirs()) { + return null; + } + } + if (!listFile.exists()) { + if (!listFile.createNewFile()) { + return null; + } + } + outputStream = new FileOutputStream(listFile); + StringBuilder fileBuilder = new StringBuilder(); + for (String file:fileArray) { + fileBuilder + .append("file") + .append(" ") + .append("'") + .append(file) + .append("'") + .append("\n"); + } + byte[] fileData = fileBuilder.toString().getBytes(); + outputStream.write(fileData, 0, fileData.length); + outputStream.flush(); + return listFile.getAbsolutePath(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } + }