From ac20dc99bf1f463365dba071973e08fffbd294b4 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 14 七月 2023 14:12:21 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/helper/FileHelper.java | 37 ++++++++++++++++++++++++++++++------- 1 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/lf/server/helper/FileHelper.java b/src/main/java/com/lf/server/helper/FileHelper.java index abc4e4e..132649a 100644 --- a/src/main/java/com/lf/server/helper/FileHelper.java +++ b/src/main/java/com/lf/server/helper/FileHelper.java @@ -7,9 +7,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; +import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.StandardCharsets; @@ -50,7 +48,7 @@ String fileName = file.getName().toLowerCase(); - int idx = fileName.lastIndexOf(StaticData.POINT); + int idx = fileName.indexOf(StaticData.POINT); if (idx == -1) { return ""; } @@ -404,7 +402,7 @@ /** * 鏍规嵁璺緞鑾峰彇鏂囦欢 */ - public static void getFilesByPath(List<File> list, String path) { + public static void getFilesByPath(List<String> list, String path) { File file = new File(path); if (file.isDirectory()) { File[] files = file.listFiles(); @@ -416,11 +414,36 @@ if (f.isDirectory()) { getFilesByPath(list, f.getPath()); } else { - list.add(f); + list.add(f.getPath()); } } } else { - list.add(file); + list.add(file.getPath()); + } + } + + /** + * 澶嶅埗鏂囦欢 + * + * @param src 婧愭枃浠� + * @param dest 鐩綍鏂囦欢 + */ + public static void copyFile(File src, File dest) throws IOException { + InputStream is = null; + OutputStream os = null; + try { + is = new FileInputStream(src); + os = new FileOutputStream(dest); + + byte[] buffer = new byte[1024]; + + int length; + while ((length = is.read(buffer)) > 0) { + os.write(buffer, 0, length); + } + } finally { + os.close(); + is.close(); } } } -- Gitblit v1.9.3