123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package edu.travel.elastic;
- import lombok.extern.slf4j.Slf4j;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- /**
- * 文件操作类
- */
- @Slf4j
- public class FileUtils {
- /**
- * 读取项目resources文件夹下的文件
- *
- * @param filePath 文件路径
- * @return 文件内容
- */
- public static String readFileContent(String filePath) {
- try {
- BufferedReader reader = new BufferedReader(new FileReader(filePath));
- String line;
- StringBuilder stringBuilder = new StringBuilder();
- while ((line = reader.readLine()) != null) {
- stringBuilder.append(line);
- }
- reader.close();
- return stringBuilder.toString();
- } catch (IOException e) {
- log.error("readFileContent error.", e);
- }
- return null;
- }
- public static void main(String[] args) {
- String filePath = "src/main/resources/es/mappings_test20231216.txt";
- String fileContent = readFileContent(filePath);
- }
- }
|