public static void main(String[] args) throws Exception {
//读取文件
InputStreamReader isr = new InputStreamReader(new FileInputStream("C:\\\\Users\\\\Administrator\\\\Desktop\\\\新建文本文档.txt"), "UTF-8");
BufferedReader wb = new BufferedReader(isr);
String line = null;
while((line=wb.readLine())!=null){
System.out.println(line);
}
isr.close();
//写入(追加)文件
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("C:\\\\Users\\\\Administrator\\\\Desktop\\\\新建文本文档.txt",true),"UTF-8");
BufferedWriter bw = new BufferedWriter(osw);
bw.newLine();
bw.write("有声有色");//将它写入缓存中,如果缓存满了则自己flush;
bw.flush();
osw.close();
}
文件流的使用
最新推荐文章于 2024-04-14 16:58:10 发布