001 package org.apache.torque.mojo; 002 003 import java.io.File; 004 import java.io.FileInputStream; 005 import java.io.FileOutputStream; 006 import java.io.InputStream; 007 import java.io.OutputStream; 008 009 public class Tail { 010 public static void main(String[] args) { 011 try { 012 int display = 3 * 1024; 013 String filename = "C:/temp/old.xml"; 014 File file = new File(filename); 015 long length = file.length(); 016 InputStream in = new FileInputStream(file); 017 in.skip(length - display); 018 OutputStream out = new FileOutputStream("C:/temp/tail.txt"); 019 byte[] buffer = new byte[1024]; 020 int readLength = 0; 021 while ((readLength = in.read(buffer, 0, buffer.length)) != -1) { 022 out.write(buffer, 0, readLength); 023 } 024 in.close(); 025 out.close(); 026 } catch (Throwable t) { 027 t.printStackTrace(); 028 } 029 } 030 031 }