我要向一个文本文件写入,但是如果这个文件存在的话,不能覆盖原有内容,接着往下写,请教该怎么实现啊,谢谢

解决方案 »

  1.   

    public boolean writeMsgToINI(String strPath, String msgData)
        {
            try
            {
        File file = new File(strPath);            if (!file.exists())
                {
                    try
                    {
                        file.createNewFile();
                    }
                    catch (IOException ex)
                    {
                    }
                }            writer = new FileWriter(strPath, true);
                bufWriter = new BufferedWriter(writer);
                bufWriter.write(msgData);
                bufWriter.close();
                writer.close();
                return true;        }
            catch (Exception ex)
            {
            }
            finally
            {
                bufWriter = null;
                writer = null;
            }
            return false;
        }
      

  2.   

    不好意思,忘了写注释new FileWriter(strPath, true);//参数列表中的boolean值即为是否要append声明为:
    public FileWriter(String fileName, boolean append)
      

  3.   

    FileWriter(String filePath, boolean b);
    第二个参数为true时,新的内容添加到原有内容之后,为false则覆盖
      

  4.   

    可以用RandomAccessFile,道理一样的。
      

  5.   

    RandomAccessFile
    http://www.ideagrace.com/html/doc/2005/06/24/00047.html
      

  6.   

    homesos(熊猫贩子)厉害,帮助大家解决了不少问题!!!!!!!