O'Reilly logo

Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition by Ivor Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.10. Summary

In this chapter, I have discussed the various ways in which you can read basic types of data from a file. The important points I have discussed include:

  • You can read a file using a FileChannel object obtained from a FileInputStream object or from a RandomAccessFile object.

  • You can use a channel obtained from a RandomAccessFile object that was created with mode "rw", "rwd", or "rws" to both read and write the file.

  • Data that is read from a file using a channel is stored in one or more buffers of type ByteBuffer.

  • You can use view buffers to interpret the data read from a file as any basic type other than boolean.

  • A memory-mapped file enables you to access data in the file as though it were resident in memory. You access a memory-mapped file through a MappedByteBuffer object.

  • Acquiring an exclusive lock on a file ensures that no other program can access the file while you hold the lock. You can obtain an exclusive lock only on a file you have opened for both reading and writing.

  • Acquiring a shared lock on a file ensures that your program has access to the file in circumstances where other programs may be accessing the same file, and protects the region of the file you have locked from being altered.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required