//StringBuffer常用于字符串追加,插入,删除
import java.io.*;
public class IOFile {
static File f=new File("test.txt");
static int count=0;
public static void main(String[] args)
{
if(!f.exists())
{
try
{
f.createNewFile();
}catch(IOException e1)
{
System.out.println(e1);
}catch(Exception e2){
System.out.println(e2);
}
}
for(int i=0;i<5;i++)
{
try
{
FileWriter fos=new FileWriter(f,true);
fos.write(String.valueOf(i));
fos.write(‘\n‘);
fos.flush();
fos.close();
}catch(FileNotFoundException e)
{
System.out.println(e);
}catch(IOException e1)
{
System.out.println(e1);
}
}
try
{
BufferedReader br=new BufferedReader(new FileReader("test.txt"));
String str=null;
for(str=br.readLine();str!=null;str=br.readLine())
System.out.println(str);
br.close();
}catch(FileNotFoundException e1)
{
System.out.println(e1);
}catch(IOException e2)
{
System.out.println(e2);
}
}
}