Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Beginner
May 2, 2018



Application Security Testing: An Integral Part of DevOps

A Better Way to Achieve Random File Access

RandomAccessFile raf = new RandomAccessFile(f, ???r???);
for (???) {
     byte b = raf.readByte();

Despite its name, the java.io.RandomAccessFile class is not very convenient for accessing files in a random-access manner, such as: seek, read, seek, read. Each of these directly issue the corresponding system calls/ioctl on the file descriptor. You can do that using MappedByteBuffer, like this:

FileInputStream in = new FileInputStream(f);
MappedByteBuffer map = in.getChannel().map(MapMode.READ_ONLY, 0, f.length());
for (???) {
byte b = map.get(pos);
Octavia Anghel
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date