当前位置: 代码迷 >> Eclipse >> 小弟我是初学者,想知道这段程序的作用?求大神赐教
  详细解决方案

小弟我是初学者,想知道这段程序的作用?求大神赐教

热度:65   发布时间:2016-04-23 01:06:43.0
我是菜鸟,想知道这段程序的作用?求大神赐教!
package io;

import java.io.*;
import java.nio.*;
import java.nio.channels.*;

public class _23ChannelCopy {
private static final int BSIZE = 1024;

@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("arguments: sourcefile destfile");
System.exit(1);
}

FileChannel 
in = new FileInputStream(args[0]).getChannel(),
out = new FileInputStream(args[0]).getChannel();

ByteBuffer buffer = ByteBuffer.allocate(BSIZE);

while (in.read(buffer) != -1) {
buffer.flip();
out.write(buffer);
buffer.clear();
}
}
}
java io

------解决方案--------------------
你查查 管道 或者 百度这个类的!应该会有一大堆教程。
从字面看,管道操作,一个读 一个写!缓冲buffer大大小就是那个size
------解决方案--------------------
这个程序是实现文件拷贝的。
需要提供2个参数,第一个是源文件所在路径,第二个是复制到的路径
  相关解决方案