File Channels and Buffers in Java I/O, Slides of Java Programming

An overview of file channels and buffers in java i/o. It explains the concept of file channels, their efficiency, and how to create a file channel object. The document also introduces the buffer class, its subclasses, and methods, such as capacity(), position(), limit(), and remaining(). It demonstrates how to write data to a file using relative and absolute put/get operations.

Typology: Slides

2012/2013

Uploaded on 04/24/2013

baishali
baishali 🇮🇳

4

(2)

84 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Chapter 10: Writing Files
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download File Channels and Buffers in Java I/O and more Slides Java Programming in PDF only on Docsity!

1

Chapter 10: Writing Files

2

Basic Information

  • You can regard the file as a series of bytes with no specific information about its structure
  • Common file extension give us some clues about the file internal structure
  • Two Modes of accessing file:
    • Sequential access
    • Random access

4

File Channels (Cont.)

Your program

Buffer Object

File Stream Object

Channel Object

5

  • Almost all classes inherit from the Buffer class. They are found in java.nio
  • ByteBuffer is the only one used in I/O
  • Viewer Buffers as CharBuffer, Double, etc.
  • Buffer capacity, position, and limit {capacity(), position(), limit(), remaining(), hasRemaining()}
  • Buff.limit(512).position(256)
  • ByteBuffer buff = ByteBuffer.allocate(1024);
  • IntBuffer intBuf = buf.asIntBuffer();
  • ByteBuffer buf = ByteBuffer.wrap(str.getBytes());
  • Relative put/get and absolute put/get

The Buffer Class