在对file的文件操作时,我如何实现用程序里插入数据而不覆盖原来的数据,使得数据自动添加。

解决方案 »

  1.   

    //第二个参数设为true
    //其他的FileWriter等都类似,楼主看看api好了FileOutputStream
    public FileOutputStream(String name,
                            boolean append)
                     throws FileNotFoundExceptionCreates an output file stream to write to the file with the specified name. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection. 
    First, if there is a security manager, its checkWrite method is called with name as its argument. If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown. 
    Parameters:
    name - the system-dependent file name
    append - if true, then bytes will be written to the end of the file rather than the beginning
      

  2.   

    ho ho,楼上的手脚快,而且直接抄JDK, PF PF