Open a writable byte channel for a file. - Java java.nio.channels

Java examples for java.nio.channels:WritableByteChannel

Description

Open a writable byte channel for a file.

Demo Code


//package com.java2s;
import java.io.File;
import java.io.FileNotFoundException;

import java.io.RandomAccessFile;

import java.nio.channels.WritableByteChannel;

public class Main {
    public static void main(String[] argv) throws Exception {
        File file = new File("Main.java");
        System.out.println(openWriteChannel(file));
    }//w w w.  ja  va 2  s .c om

    /**
     * Open a writable byte channel for a file.
     * 
     * @param file
     *            A <code>File</code>.
     * @return A <code>WritableByteChannel</code>.
     * @throws FileNotFoundException
     */
    public static WritableByteChannel openWriteChannel(final File file)
            throws FileNotFoundException {
        return new RandomAccessFile(file, "rws").getChannel();
    }
}

Related Tutorials