【问题标题】:Copy a file from local drive to share drive using JCIFS performance issue使用 JCIFS 性能问题将文件从本地驱动器复制到共享驱动器
【发布时间】:2015-06-01 13:45:43
【问题描述】:

我正在使用以下 JCIFS 代码将文件从本地磁盘复制到共享驱动器

public boolean copyFiles(String srcFilePath, String destinationFileName) throws Exception {
    boolean successful = false;
    SmbFileOutputStream sfos = null;

    try {
        String user = USER_NAME + ":" + PASSWORD;
        System.out.println("User: " + user);

        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("mydomain",USER_NAME,PASSWORD);
        Config.setProperty("resolveOrder", "DNS");

        String destinationFilePath = NETWORK_FOLDER +"/" +destinationFileName;

        SmbFile sFile = new SmbFile(destinationFilePath, auth);
        sfos = new SmbFileOutputStream(sFile);
    // sfos.write(getBytesFromFile(new File(srcFilePath))); -- 1st approach
       // Files.copy(new File(srcFilePath).toPath(),sfos); -- 2nd approach
        FileInputStream fis = new FileInputStream(srcFilePath);

        BufferedReader brl = new BufferedReader(new InputStreamReader(fis));
        String b = null;
        while ((b = brl.readLine()) != null) {
            sfos.write(b.getBytes());
        }
        sfos.flush();

        successful = true;
        System.out.println("Successful" + successful);
    } catch (Exception e) {
        successful = false;
        e.printStackTrace();
    } finally {
        if (sfos != null) {
            sfos.close();
        }
    }
    return successful;
}

复制 10 mb 文件需要 10 多分钟。而当我直接复制同一个文件时,大约需要 1 分钟。我尝试了 3 种方法来复制文件(请参阅代码的注释部分),但它们都没有显示出任何显着差异。

有什么办法可以提高 JCIFS 的性能吗?

【问题讨论】:

  • 同样的问题。 Deos 有人知道加快文件传输的任何设置/解决方法吗?

标签: java jcifs


【解决方案1】:

作为一种解决方法,我已安装共享驱动器并将文件复制到该驱动器中。

【讨论】:

    猜你喜欢
    • 2016-12-28
    • 2012-11-01
    • 2013-01-22
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    相关资源
    最近更新 更多