Posted By:
Diego_Saverino
Posted On:
Tuesday, May 21, 2002 05:07 AM
Using an example found in this forum as a program written by me I've discovered that don't work on remote files. The program runs on NT and the file I want read is on a mapped network disk. Does anyone know why after reached the EOF the file seems not been updated? Has anyone some suggestion? Here the code I've used: import java.io.*; public class Tail { public Tail(File f) throws java.io.IOException, java.lang.InterruptedException{ int pos = 0; RandomAccessFile file = new RandomAccessFile(f, "r"); pos = (int)file.length() - (int)Math.min(400, file.length()); file.seek(pos); for (;true; Thread.currentThread().sleep(2000)){ int
More>>
Using an example found in this forum as a program written by me I've discovered that don't work on remote files.
The program runs on NT and the file I want read is on a mapped network disk. Does anyone know why after reached the EOF the file seems not been updated?
Has anyone some suggestion?
Here the code I've used:
import java.io.*;
public class Tail {
public Tail(File f) throws java.io.IOException, java.lang.InterruptedException{
int pos = 0;
RandomAccessFile file = new RandomAccessFile(f, "r");
pos = (int)file.length() - (int)Math.min(400, file.length());
file.seek(pos);
for (;true; Thread.currentThread().sleep(2000)){
int l = (int)(file.length()-pos);
if (l
<= 0) continue;
byte[] buf = new byte[l];
int read = file.read(buf,0, l);
String out = new String(buf, 0,l);
System.out.print(out);
pos = pos+l;
}
}
public static void main(String[] args) {
try{
Tail tail1 = new Tail(new File(args[0]));
}
catch (ArrayIndexOutOfBoundsException a){
System.out.println("Usage : Tail
");
System.exit(1);
}
catch (java.io.IOException io){
System.err.println(io.getMessage());
System.exit(1);
}
catch (Exception xe){
xe.printStackTrace();
System.exit(1);
}
}
}
<<Less