import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FileRW {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String path = "e:/a.txt";
writeFile(path);
readFile(path);
}
/**
* 写文件
* @param path
* @throws IOException
*/
public static void writeFile(String path) throws IOException {
File f = new File(path);
BufferedWriter bfw = new BufferedWriter(new FileWriter(f));
bfw.append("wff\n");
bfw.append("东北电力大学");
bfw.flush();
bfw.close();
}
/**
* 读文件
* @param path
* @throws IOException
*/
public static void readFile(String path) throws IOException{
File f = new File(path);
BufferedReader bfr=new BufferedReader(new FileReader(f));
String line=null;
StringBuffer sb=new StringBuffer();
while((line=bfr.readLine())!=null){
sb.append(line+"\n");
}
bfr.close();
System.out.println(sb.toString());
}
}
文件读写--BufferedReader/BufferedWriter
最新推荐文章于 2021-09-03 10:04:17 发布