CharBuffer: capacity() : CharBuffer « java.nio « Java by API






CharBuffer: capacity()

  
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;

public class MainClass {

  public static void main(String[] args) {
    File aFile = new File("afile.txt");
    FileOutputStream outputFile = null;
    try {
      outputFile = new FileOutputStream(aFile, true);
      System.out.println("File stream created successfully.");
    } catch (FileNotFoundException e) {
      e.printStackTrace(System.err);
    }
    ByteBuffer buf = ByteBuffer.allocate(1024);
    System.out.println("\nByte buffer:");
    System.out.printf("position = %2d  Limit = %4d  capacity = %4d%n", buf.position(), buf.limit(),
        buf.capacity());

    // Create a view buffer
    CharBuffer charBuf = buf.asCharBuffer();
    System.out.println("Char view buffer:");
    System.out.printf("position = %2d  Limit = %4d  capacity = %4d%n", charBuf.position(), charBuf
        .limit(), charBuf.capacity());
    try {
      outputFile.close(); // Close the O/P stream & the channel
    } catch (IOException e) {
      e.printStackTrace(System.err);
    }
  }
}

           
         
    
  








Related examples in the same category

1.CharBuffer: allocate(int capacity)
2.CharBuffer: array()
3.CharBuffer: arrayOffset()
4.CharBuffer: flip()
5.CharBuffer: get()
6.CharBuffer: hasArray()
7.CharBuffer: hasRemaining()
8.CharBuffer: limit()
9.CharBuffer: limit(int newLimit)
10.CharBuffer: position()
11.CharBuffer: put(char c)
12.CharBuffer: put(String str)
13.CharBuffer: slice()
14.CharBuffer: subSequence(int start, int end)
15.CharBuffer: wrap(CharSequence csq)
16.CharBuffer: wrap(char[] array, int offset, int length)