集册 Java实例教程 从通道创建流

从通道创建流

—— 从频道创建流

欢马劈雪     最近更新时间:2020-01-02 10:19:05

504
从频道创建流

import java.io.File;

import java.io.IOException;
/** from 
NowJava.com - 时  代  Java**/

import java.io.InputStream;

import java.io.OutputStream;

import java.io.RandomAccessFile;

import java.nio.channels.Channels;

import java.nio.channels.FileChannel;


public class Main {

  public static void main(String[] argv) {

    try {

      // Create a read/writable file channel

      File file = new File("filename");

      FileChannel channel = new RandomAccessFile(file, "rw").getChannel();


      OutputStream os = Channels.newOutputStream(channel);


      InputStream is = Channels.newInputStream(channel);
展开阅读全文