废话不多说,直接赋代码
String filePath = “文件的绝对路径+文件名称”;
File file = new File(filePath);
StringBuffer sbf = new StringBuffer();
int line = 1;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), “UTF-8”))😉 {
String content = null;
while ((content = reader.readLine()) != null) {
sbf.append(content);
line++;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return sbf.toString();
}