public static String getAbsolutePath(String fileName) {
ClassPathResource resource = new ClassPathResource(fileName);
File file = null;
try {
file = resource.getFile();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return file.getAbsolutePath();
}
public static String readFileContent(String fileName) throws IOException {
File file = new File(fileName);
BufferedReader bf = new BufferedReader(new FileReader(file));
String content = "";
StringBuilder sb = new StringBuilder();
content = bf.readLine();
while (content != null) {
sb.append(content);
sb.append("\n"); // 添加换行符
content = bf.readLine();
}
bf.close();
return sb.toString();
}
ClassPathResource resource = new ClassPathResource(fileName);
File file = null;
try {
file = resource.getFile();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return file.getAbsolutePath();
}
public static String readFileContent(String fileName) throws IOException {
File file = new File(fileName);
BufferedReader bf = new BufferedReader(new FileReader(file));
String content = "";
StringBuilder sb = new StringBuilder();
content = bf.readLine();
while (content != null) {
sb.append(content);
sb.append("\n"); // 添加换行符
content = bf.readLine();
}
bf.close();
return sb.toString();
}