transferto方法的应用_NIO的transferTo方法

在本文中,作者遇到了使用Java NIO的transferTo方法进行文件间数据传输时遇到的问题。代码示例展示了从'E://om_seat20140628.txt'读取数据并尝试写入'E://aa.txt',但似乎数据没有正确加载到管道。作者寻求社区的帮助以解决这个问题。
摘要由CSDN通过智能技术生成

大家好!我最近在做NIO,为什么我使用NIO的transferTo方法貌似数据没有加载到管道

求大神指点

package com.etwin.opps.policy.mvc;

import java.io.RandomAccessFile;

import java.nio.ByteBuffer;

import java.nio.channels.FileChannel;

import org.slf4j.Logger;

import com.modules.util.Log;

public class NioChannelControllerTest {

private final static Logger logger=Log.get();

/**

* @param args

*/

public static void main(String[] args) {

logger.info("Start NioChannelControllerTest==");

try {

RandomAccessFile randomFile=new RandomAccessFile("E://om_seat20140628.txt", "rw");

//开通通道

FileChannel fileChannel=randomFile.getChannel();

RandomAccessFile randomAccFile=new RandomAccessFile("E://aa.txt","rw");

//开通通道

FileChannel fileChan=randomAccFile.getChannel();

long count=0;

fileChan.transferTo(count,fileChannel.size(), fileChannel);

ByteBuffer byteBu=ByteBuffer.allocate(1024);

int num=fileChan.read(byteBu);

while(num!=-1){

fileChan.write(byteBu);

}

} catch (Exception e) {

logger.info(e.getMessage());

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值