JCIFS:文件检索太慢而无法使用 [英] JCIFS: file retrieval is too slow to be usable

查看:229
本文介绍了JCIFS:文件检索太慢而无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在测试 JCIFS 以访问Windows共享。它完全无法使用非常缓慢。

I was just testing JCIFS for accessing Windows shares. It is very slow to the point of being completely unusable.

import jcifs.smb.*;

class First {
    public static void main(String[] args) throws Exception {
    try {
        //jcifs.Config.setProperty( "jcifs.netbios.wins", "192.168.1.220" );
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain.com", "Administrator", "password");

        SmbFile f = new SmbFile("smb://10.17.15.12/Share/xml/file.xml", auth);
        SmbFileInputStream in = new SmbFileInputStream(f);
        byte[] b = new byte[8192];
        int n;
        while(( n = in.read( b )) > 0 ) {
        System.out.write( b, 0, n );
        }
    } catch (SmbException smbe) {
        System.err.println(smbe.getNtStatus());
        System.err.println(smbe.toString());
        System.err.println(smbe.getCause());
    }
    }
}

这需要很长时间才能完成初始输出到后来的读取也很慢。任何想法如何使用它?我也可以通过这种方式编写Java代码以便携式方式访问Windows共享

It takes very long time for initial output to come and subsequent reads are also very slow. Any ideas how to use it? Any alternatives by which I can write Java code to access the Windows shares in a portable way are also welcome

推荐答案

我找到了某个地方SmbFileInputStream没有自己的缓冲,因此是缓慢的原因。在BufferedInputStream中包装SmbFileInputStream解决了这个问题。

I found somewhere that SmbFileInputStream doesn't do its own buffering and hence the reason for being slow. Wrapping SmbFileInputStream in a BufferedInputStream solved the problem.

 SmbFile sFile = new SmbFile(path, authentication);

 BufferedInputStream buf = new BufferedInputStream(new SmbFileInputStream(sFile));

这篇关于JCIFS:文件检索太慢而无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆