我有个例子
import java.io.*;
import java.applet.Applet;public class myFile
{
public myFile()
{
init();
RecordAppend("xuguo");
}

public void init()
{
try
{
  String Record="zhoukun";
          String myFilePath="D:/jspServer";
      String myFileName="myWriteFile.txt";
      File dir=new File(myFilePath,"newFile");
      dir.mkdir();
      File f=new File(dir,myFileName);
      FileOutputStream o=new FileOutputStream(f);
      BufferedOutputStream myin=new BufferedOutputStream(o);
      byte c[]=Record.getBytes();
      myin.write(c);
      myin.flush();
      myin.close();
    }
    catch(IOException e)
    {
     System.out.println(e);
    }
}

public void RecordAppend(String strAppend)
{
try
{
  int filelength;
  int writelength;
          String myFilePath="D:/jspServer/newFile";
      String myFileName="myWriteFile.txt";
      File f=new File(myFilePath,myFileName);
      FileOutputStream o=new FileOutputStream(f);
      BufferedOutputStream myin=new BufferedOutputStream(o);
      byte c[]=strAppend.getBytes();
      filelength=(int)f.length();
      writelength=strAppend.length();
      
      myin.write(c,filelength,writelength);
      myin.flush();
      myin.close();
    }
    catch(IOException e)
    {
     System.out.println(e);
    }
}

public static void main(String args[])
{
new myFile();
}
}