import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
// 写文件至少需要 BufferedWriter、FileWriter 两个类
try (BufferedWriter bw = new BufferedWriter(new FileWriter("d:/test.txt"))) {
for (int i = 0; i < 10; i++) {
bw.write(i + "");
// 换行
bw.newLine();
}
}
// 读文件至少需要 BufferedReader、FileReader 两个类
try (BufferedReader br = new BufferedReader(new FileReader("d:/test.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
}