1 package org.apache.torque.mojo; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileOutputStream; 6 import java.io.InputStream; 7 import java.io.OutputStream; 8 9 public class Tail { 10 public static void main(String[] args) { 11 try { 12 int display = 3 * 1024; 13 String filename = "C:/temp/old.xml"; 14 File file = new File(filename); 15 long length = file.length(); 16 InputStream in = new FileInputStream(file); 17 in.skip(length - display); 18 OutputStream out = new FileOutputStream("C:/temp/tail.txt"); 19 byte[] buffer = new byte[1024]; 20 int readLength = 0; 21 while ((readLength = in.read(buffer, 0, buffer.length)) != -1) { 22 out.write(buffer, 0, readLength); 23 } 24 in.close(); 25 out.close(); 26 } catch (Throwable t) { 27 t.printStackTrace(); 28 } 29 } 30 31 }