StringBuffer commonly used for string append, insert, delete
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);
}
}
}
Java file Read and write Example 1