Java IO文件操作

//读文件 BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("fileUrl"))));
String tempStr = "";
while((tempStr = br.readLine())!=null){
	System.out.println(tempStr);
}
//写文件 PrintWriter
PrintWriter pw = new PrintWriter(new File("fileUrl"));
pw.println("每一次输出一行到文件");
//写文件 BufferedWriter
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("fileUrl"))));
bw.write("");

//一次读取文件所有内容
File file = new File("filePath");
Long l = file.length();
byte[] fc = new byte[l.intValue()];
FileInputStream fis = new FileInputStream(file);
fis.read(fc);
fis.close();
String str = new String(fc,"UTF-8");

你可能感兴趣的:(java io)