Code example for FileChannel

Methods: close, position, read

0
				return new RandomAccessFile(fileName, "r");
			} 
 
			private BufferedReader reader(RandomAccessFile file,
					final FileChannel channel) throws IOException {
				channel.position(lastPosition);
				lastPosition = file.length();
 
				return new BufferedReader(Channels.newReader(channel,
						"ISO-8859-1")) { 
					@Override 
					public void close() throws IOException { 
						lastFewBytes = lastFewBytes(channel);
						super.close(); 
					} 
				}; 
			} 
 
			private BufferedReader close(FileChannel channel)
					throws IOException { 
				channel.close();
				return null; 
			} 
 
			private byte[] lastFewBytes(FileChannel channel) throws IOException {
				long beforeLastFew = Math.max(0, lastPosition - 100);
				ByteBuffer buffer = ByteBuffer
						.allocate((int) (lastPosition - beforeLastFew));
				channel.read(buffer, beforeLastFew);
				return buffer.array();
			} 
		}; 
	} 
}