I don't want to give away all my source code, but the following fragment
may be helpful!
private long check(RandomAccessFile log, StringBuffer logBuffer, long oldLength)
throws Exception
{
long newLength = log.length();
if (newLength < oldLength)
{
// Log was truncated, start at beginning
oldLength = 0;
}
long offset = oldLength;
byte[] bytes = new byte[80];
while (offset < newLength)
{
log.seek(offset);
int n = log.read(bytes);
if (n == -1)
{
return newLength; // Perhaps file was truncated.
}
for (int i = 0; i < n; i++)
{
char c = (char)bytes[i];
if (c == '\n')
{
check(logBuffer.toString().trim());
logBuffer.setLength(0);
}
else
{
logBuffer.append(c);
}
}
offset += n;
}
return newLength;
}
Eugene Voznesensky wrote:
>
> Hi
>
> Thank you.
>
> Do you have any idea how to read an added part of the file?
>
> E.
>
> > -----Original Message-----
> > From: Jeff Martin [mailto:[EMAIL PROTECTED]]
> > Sent: m/28/00 03:07 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: How to read a file changes?
> >
> >
> > Eugene Voznesensky wrote:
> > > I have implement the next in my Java program:
> > >
> > > To be notified when log file changed and read
> > > added part for further processing.
> >
> > A quick way would be to use File.length() to keep checking if
> > the file has
> > grown some.
> >
> > Jeff
> >
> > ==============================================================
> > =============
> > To unsubscribe, send email to [EMAIL PROTECTED] and
> > include in the body
> > of the message "signoff EJB-INTEREST". For general help,
> > send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
--
________________________________________________________________________________
Evan Ireland Sybase EAServer Engineering [EMAIL PROTECTED]
Wellington, New Zealand +64 4 934-5856
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".