本帖最后由 殷俊 于 2015-3-26 12:05 编辑
代码如下- /*
- 复制
- */
- import java.io.*;
- class IODemo1
- {
- public static void main(String[] args)
- {
- FileWriter fw=null;
- FileReader fr=null;
- try
- {
- fw=new FileWriter("FileDemo1.txt");
- fr=new FileReader("FileDemo.txt");
- FileWriter fw1=new FileWriter("FileDemo.txt",true);
- fw1.write("你好,生活如此残酷,我却如此淡定!!\r\n这样不好不好!!");
- fw1.flush();
- char[] buf=new char[1024];
- int num=0;;
- while((num=fr.read(buf))!=-1)
- {
- fw.write(buf,0,num);
- }
- }
- catch (IOException e)
- {
- System.out.println("Hello World!");
- }
- finally
- {
- try
- {
- if(fw!=null)
- fw.close();
- }
- catch (IOException e)
- {
- System.out.println("Hello World!");
- }
- try
- {
- if(fr!=null)
- fr.close();
- }
- catch (IOException e)
- {
- System.out.println("Hello World!");
- }
- }
-
- }
- }
复制代码
|
|