Java 读写文件

62 阅读1分钟

Java读文件

读行

读行用BufferedReader类,自己去看构造方法,读行使用readLine()即可

String path = "";
File file = new File(path);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = "";
while (StringUtils.isNotBlank(line = reader.readLine())) {
    // 对读取的每一行进行操作...
}

Java写文件

String writePath = "";
String content = "";
Files.write(Paths.get(writePath), content.getBytes(), APPEND);