Article View: borland.public.jbuilder.java.api
Article #3525Re: adding a new line to a log file
From: Carlos Vega
Date: Mon, 15 Dec 1997 00:00
Date: Mon, 15 Dec 1997 00:00
46 lines
1859 bytes
1859 bytes
Dana Soward wrote:
> Thank you for the example, it works great, but how can i get it to write
> to the next line each time i write to the file? right now it just writes
> over the old line. i have tried \n, but it just displays a block at the
> end of the line. (like this ) any ideas? thanx again.
>
> Dana Soward
Here is a small piece o code I wrote in order to generate a log file for a
server program.
You only have to addapt it to your application purposes. It runs under
JDK1.1.4. I hope it to be useful.
private static void printLog(String path, String result) {
try {
// Generates the message for the log file
Date date = new Date();
InetAddress addr = InetAddress.getLocalHost();
String log = date + " " +
addr.getHostName() +
" java FtpAut \nFichero o directorio " + path +
" Enviado con resultado: " +
result + "\n";
// Opens the file for reading-writing
RandomAccessFile logFile = new RandomAccessFile(LOGFILE,"rw");
// Adds the log at the end of the file
logFile.seek(logFile.length());
logFile.writeBytes(log);
logFile.close();
}
catch(Exception e) {
}
}
};
Carlos Prados Bocos
e-mail: cprados@ods.sligos.es
ODS-ATOS group.
Technical Details
Message-ID:
<34953644.7F344BC2@ods.jet.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<342E9781.76EE@ussw.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,8139989bb8009f33,start X-Google-Attributes: gid1089d0,public From: Carlos Vega <carlos-vega@ods.jet.es> Subject: Re: adding a new line to a log file Date: 1997/12/15 Message-ID: <34953644.7F344BC2@ods.jet.es> X-Deja-AN: 298356001 Content-Transfer-Encoding: 8bit References: <342E9781.76EE@ussw.com> Content-Type: text/plain; charset=iso-8859-1 Organization: ODS, S.A. Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api