CharBuffer: put(String str) : CharBuffer « java.nio « Java by API






CharBuffer: put(String str)

  
/*
 * Output:
 

 */

import java.io.File;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class MainClass {
  public static void main(String[] args) {
    try {
      File aFile = new File("test.txt");

      FileOutputStream outputFile = null;
      outputFile = new FileOutputStream(aFile, true);
      FileChannel outChannel = outputFile.getChannel();

      ByteBuffer buf = ByteBuffer.allocate(200);

      buf.putInt(10).asCharBuffer().put("www.java2s.com");

      buf.position(10).flip();
      outChannel.write(buf);
      buf.clear();

      outputFile.close();

    } catch (Exception e) {
      e.printStackTrace();

    }

  }
}

           
         
    
  








Related examples in the same category

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