【Java】读写文本文件

package rw;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader; public class test {
public static void main(String[] agrc) throws IOException
{
//写入文件
FileOutputStream out = new FileOutputStream("test.txt");
for(int i=0;i<100;i++)
{
String s = "this line is " + i+"\n";
out.write(s.getBytes());
}
out.close(); //读取文件
FileInputStream in = new FileInputStream("test.txt"); // 读取文件路径
BufferedReader br = new BufferedReader(new InputStreamReader(in));
for(int i=0;i<100;i++)
{
String line = br.readLine();
System.out.println(line);
}
br.close();
in.close();
}
}
上一篇:【vue】npm run mock & npm run dev 无法同时运行的解决


下一篇:JNI-Thread中start方法的调用与run方法的回调分析