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