先建立一个File对象,然后用流写进去try{
File f=new File("classjava.txt");
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream out=new DataOutputStream(fos);
out.writerUTF("hello,classjava");
}catch(IOException)
{}

解决方案 »

  1.   

    RandomAccessFile rf=null;
    try
    {
    rf=new RandomAccessFile("error.txt","rw");
    rf.seek(rf.length());
    rf.writeBytes("\n Hello");
    rf.writeBytes("\n World");
    rf.close();
    }
    catch(IOException ioe)
    {
    writeErr(ioe);
    }
      

  2.   

    import java.io.*;class IOTest
    {
    public static void main(String[] args) throws IOException
    {
    FileOutputStream f_write = new FileOutputStream("d:/stream.txt");
    DataOutputStream dos = new DataOutputStream(f_write);

    InputStreamReader read = new InputStreamReader(System.in);
    BufferedReader istr = new BufferedReader(read);

    System.out.println("Input:");
    String str ;
    str = String.valueOf(istr.readLine());
    try
    {
    dos.writeBytes(str);
     }
    catch(Exception e) {throw new InternalError("Unexpected CloneNotSUpportedException: " + e.getMessage());}
    finally
    {
    dos.close();
     }
     
    FileInputStream f_read = new FileInputStream("d:/stream.txt");
    DataInputStream dis = new DataInputStream(f_read);
    try
    {
    System.out.println(dis.readLine());
     }
    catch(Exception e)  {throw new InternalError("Unexpected CloneNotSUpportedException: " + e.getMessage());}
        finally
        {
         dis.close();
         }
     }
     }能读能写!