Java在文件的末尾添加数据

来源:互联网 发布:关于网络暴力的演讲 编辑:程序博客网 时间:2024/05/17 04:27
 在文件的末尾添加数据:
public void appendToFile(String str) 
   
{
      String  filename 
= "d:/fp/asout.txt"

      FileOutputStream stream;

      OutputStreamWriter writer;

      
try 

      
{

         stream 
= new FileOutputStream(filename, true);

         writer 
= new OutputStreamWriter(stream);
         writer.write (
" ");
         writer.write(str);

         writer.close();

         stream.close();

      }


      
catch(Exception e) 

      
{
            e.getStackTrace ();
      }


   }
测试通过
原创粉丝点击