Java中的SendFile和transferTo

Java中的SendFile和transferTo,java,linux,transfer,sendfile,zero-copy,Java,Linux,Transfer,Sendfile,Zero Copy,我使用的是CentOs内核版本2.6.32。我计划使用NIO做一个有无transferTo(sendFile)的测试。我的测试是将1GB文件从一个目录复制到另一个目录。但是,由于使用transferTo(),我没有发现任何显著的性能改进。请让我知道文件到文件sendFile是否在Linux内核中真的有效,还是仅文件到套接字有效?我需要为sendFile启用任何功能吗 示例代码: private static void doCopyNIO(String inFile, String outFi

我使用的是CentOs内核版本2.6.32。我计划使用NIO做一个有无transferTo(sendFile)的测试。我的测试是将1GB文件从一个目录复制到另一个目录。但是,由于使用transferTo(),我没有发现任何显著的性能改进。请让我知道文件到文件sendFile是否在Linux内核中真的有效,还是仅文件到套接字有效?我需要为sendFile启用任何功能吗

示例代码:

  private static void doCopyNIO(String inFile, String outFile) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        FileChannel cis = null;
        FileChannel cos = null;

        long len = 0, pos = 0;

        try {
            fis = new FileInputStream(inFile);
            cis = fis.getChannel();
            fos = new FileOutputStream(outFile);
            cos = fos.getChannel();
            len = cis.size();
            /*while (pos < len) {
                pos += cis.transferTo(pos, (1024 * 1024 * 10), cos);    // 10M
            }*/
            cis.transferTo(0, len, cos);
            fos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } 
}
private静态void doCopyNIO(字符串填充、字符串输出文件){
FileInputStream fis=null;
FileOutputStream=null;
filechannelcis=null;
FileChannel cos=null;
长透镜=0,位置=0;
试一试{
fis=新文件输入流(infle);
cis=fis.getChannel();
fos=新文件输出流(输出文件);
cos=fos.getChannel();
len=cis.size();
/*while(pos
sendfile()系统调用将文件发送到套接字。splice()系统调用可用于文件。请看这里: