🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18322

Append text to a file

#18322
From: KA.Quante
Date: Wed, 08 Jul 1998 00:00
38 lines
1595 bytes
Hello,
I want to add text to a file. Therefor I have an FileOutputStream
with append = true, but this parameter is not defined when I compile
it with JDK 1.1.5/6 but described in the documentation.

How can I append text to a file and don't overwrite it every time?

Kai

Example code(s):

try{
  date.getTime();
  // write the file
  File oFNew = new File( file );
  FileOutputStream oFOS  = new FileOutputStream( oFNew, true );
  DataOutputStream file  = new DataOutputStream( oFOS );

  // Header
  file.writeBytes( df.format( date ) + ": " + log + "\n" );
  file.flush();
  oFOS.close();
  return true;
}
  catch( Exception e){
  System.out.println( "Error writing log file.");
  return false;
}

---------------
Better way:
FileOutputStream FStream = new FileOutputStream(file, true);
PrintWriter PW = new PrintWriter( FStream );
PW.println( df.format( date ) + ": " + log );
PW.close();

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
Technical Details
Message-ID: <6nv5r8$tha$1@nnrp1.dejanews.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,794288f1cb35bc39,start
X-Google-Attributes: gidf74b3,public
From: KA.Quante@lineas.de
Subject: Append text to a file
Date: 1998/07/08
Message-ID: <6nv5r8$tha$1@nnrp1.dejanews.com>
X-Deja-AN: 369356439
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Wed Jul 08 07:07:20 1998 GMT
Newsgroups: borland.public.jbuilder.java.language
X-Http-User-Agent: Mozilla/4.05 [en] (WinNT; I) via Squid Cache version 1.0.8