java文件流处理
File f=new File((“lll.xxx");
BufferedReader reader = new BufferedReader(new FileReader(f));
String line;
while((line=reader.readLine())!=null){
strContent+=line;
}
File f = new File("E:\99.inc");
InputStreamReader read = new InputStreamReader (new FileInputStream(f),"UTF-8");
BufferedReader reader=new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
BufferedReader reader = new BufferedReader(new FileReader(f));
String line;
while((line=reader.readLine())!=null){
strContent+=line;
}
File f = new File("E:\99.inc");
InputStreamReader read = new InputStreamReader (new FileInputStream(f),"UTF-8");
BufferedReader reader=new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
向文本文件中追加写入内容
try {
FileWriter filewriter = new FileWriter(new File(”text.txt”), true);
String content = “aaaaaa”;
filewriter.write(content);
filewriter.close();
} catch (IOException e) {
e.printStackTrace();
}
FileWriter filewriter = new FileWriter(new File(”text.txt”), true);
String content = “aaaaaa”;
filewriter.write(content);
filewriter.close();
} catch (IOException e) {
e.printStackTrace();
}
FileWriter(new File(”text.txt”), true)中“true”是设置为向文件中追加内容