Java ByteBuffer Write writeFile(File file, ByteBuffer bb)

Here you can find the source of writeFile(File file, ByteBuffer bb)

Description

write File

License

Open Source License

Declaration

public static boolean writeFile(File file, ByteBuffer bb) 

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.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
    public static boolean writeFile(File file, String str) {
        try {/* w  w  w.  j a va  2s. c  om*/
            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            writer.write(str);
            writer.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static boolean writeFile(File file, ByteBuffer bb) {
        try {
            FileChannel wChannel = new FileOutputStream(file, false).getChannel();
            wChannel.write(bb);
            wChannel.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static boolean writeFile(File file, ByteBuffer bb, long offset) {
        try {
            FileChannel wChannel = new RandomAccessFile(file, "rw").getChannel();
            wChannel.write(bb, offset);
            wChannel.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. writeDouble(double v, ByteBuffer buffer)
  2. writeEmpty(final ByteBuffer buffer, final int type)
  3. writeFakeImageData(ByteBuffer out, int lzwMinCodeSize)
  4. writeFFloat(ByteBuffer buffer, float value)
  5. writeFile(ByteBuffer data, File destination)
  6. writeFile(File file, ByteBuffer buffer)
  7. writeFileFragment(FileChannel fc, long pos, ByteBuffer fragment)
  8. writeFloat(ByteBuffer buffer, float f)
  9. writeFromBuffer(SocketChannel channel, ByteBuffer buf, int sleepMsecs)