Java ByteBuffer Write write(ByteBuffer data, String filename, boolean append)

Here you can find the source of write(ByteBuffer data, String filename, boolean append)

Description

write

License

Open Source License

Declaration

public static void write(ByteBuffer data, String filename, boolean append) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import java.nio.ByteBuffer;

import java.nio.channels.FileChannel;

public class Main {
    public static void write(ByteBuffer data, String filename, boolean append) throws IOException {
        File file = new File(filename);
        file.getParentFile().mkdirs();//w ww.ja  v  a2 s  .  c om
        write(data, file, append);
    }

    public static void write(ByteBuffer data, File file, boolean append) throws IOException {
        @SuppressWarnings("resource")
        FileChannel out = new FileOutputStream(file, append).getChannel();
        out.write(data);
        out.close();
    }

    public static void write(CharSequence data, File file, boolean append) throws IOException {
        BufferedWriter wirter = new BufferedWriter(new FileWriter(file, append));
        wirter.write(data.toString());
        wirter.flush();
        wirter.close();
    }
}

Related

  1. write(ByteBuffer bb, int elementWidth, long value)
  2. write(final byte[] array, final int offset, final int end, final ByteBuffer outBB)
  3. write(GatheringByteChannel out, ByteBuffer[] buffers, int offset, int length)
  4. write(MappedByteBuffer buffer, int pos, String asciString)
  5. write(SocketChannel channel, ByteBuffer b, PrimitiveIterator.OfInt iterator)