|
@@ -7,15 +7,9 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-import java.io.BufferedOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Random;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -179,4 +173,24 @@ public class FileUtil {
|
|
|
saveToFile(data, new File(filePath));
|
|
|
}
|
|
|
|
|
|
+ public static List<String> readFile(File file) {
|
|
|
+ List<String> lines = new ArrayList<>();
|
|
|
+ if (!file.exists() || !file.isFile()) {
|
|
|
+ return lines;
|
|
|
+ }
|
|
|
+
|
|
|
+ final String encoding = "UTF-8";
|
|
|
+ try (FileInputStream fos = new FileInputStream(file);
|
|
|
+ InputStreamReader isr = new InputStreamReader(fos, encoding);
|
|
|
+ BufferedReader br = new BufferedReader(isr);) {
|
|
|
+ String line;
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ lines.add(line);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return lines;
|
|
|
+ }
|
|
|
+
|
|
|
}
|