readline
public class BufferedReaderSpecial {
public static void main(String[] args) {
try (BufferedReader reader = new BufferedReader(new FileReader("file\\day26\\src"))) {
// 1. 定义一个字符串,用来接收每一行读取到的数据
String line = "";
// 2. 循环读取数据
while ((line = reader.readLine()) != null) {
// 3. 将读取到的数据输出
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
newline
public class BufferedWriterSpecial {
public static void main(String[] args) {
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("file\\day26\\dst"))) {
bufferedWriter.write("hello world");
bufferedWriter.newLine();
bufferedWriter.write("你好,世界");
bufferedWriter.newLine();
bufferedWriter.write("end");
} catch (IOException e) {
e.printStackTrace();
}
}
}