View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }