比如说 有a.txt 文件 文件里 有 内容 然后我想在哪个原有的内容下面 添加一些 内容。请高手指教

解决方案 »

  1.   

    new FileInputStream(new File("a.txt"),true);
      

  2.   

    File file = new File("xx.txt");
            InputStreamReader inputReader = null;
            BufferedReader bufferReader = null;
            OutputStream outputStream = null;
            try
            {
                InputStream inputStream = new FileInputStream(file);
                inputReader = new InputStreamReader(inputStream);
                bufferReader = new BufferedReader(inputReader);
                
                // 读取一行
                String line = null;
                StringBuffer strBuffer = new StringBuffer();
                String newLine = "\n";
                
                while ((line = bufferReader.readLine()) != null)
                {
                    
                    if (判断什么地方加你的东西)     
                    {
                      
                    }
                    else
                    {
                        strBuffer.append(line);
                        strBuffer.append(newLine);
                    }
                    
                }
                outputStream = new FileOutputStream(file);
                //写文件
                outputStream.write(strBuffer.toString().getBytes());
                
            }
            catch (IOException e)
            {
                LOG.error(e.getMessage());
            }
            finally
            {
                OtherUtilAPI.closeAll(outputStream, bufferReader, inputReader);
            }
            
      

  3.   

    不是上个帖子都回答了么FileWriter