首页 > 解决方案 > 查找 samba 共享文件总大小的方法,JCIFS length() 除外

问题描述

我需要找到一组关于使用带有 JCIFS 的 Java 代码的 samba 共享文件的详细信息。即使 getDiskFreeSpace() 打印出一个值,“length()”,即总大小,每次都打印为 0。我需要一种方法来帮助我找出这个总大小。

有谁知道我可以尝试的类似 API,或者我应该做什么才能打印出一个值,而不是 0?代码片段:

try
        {
            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("*****", "username", "password");
            SmbFile smb = new SmbFile("smb://*****/Global/FR/342/WM_GER",auth);
            smb.connect();
            System.out.println("free space : "+smb.getDiskFreeSpace());
            System.out.println("total space : "+smb.length()); // prints 0
            Long percent = (smb.length() - smb.getDiskFreeSpace())/smb.length(); // gives exception because length is 0
            System.out.println("percent : "+percent);

            BigDecimal filesystemUsedSpace = BigDecimal.valueOf(smb.getDiskFreeSpace());
            System.out.println("filesystemUsedSpace "+filesystemUsedSpace);
            System.out.println("smb.getDiskFreeSpace() "+smb.getDiskFreeSpace());
            System.out.println("smb.getContentLength() "+smb.getContentLength());
            System.out.println("smb.getContentLengthLong() "+smb.getContentLengthLong());
            System.out.println("smb.getType() "+smb.getType());
        }
        catch (MalformedURLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (SmbException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

输出(当注释“百分比”变量时,如果不是由于 length() 的 0 值,它会给出异常):

free space : 10354356224
total space : 0
filesystemUsedSpace 1011870294016
smb.getDiskFreeSpace() 1011870294016
smb.getContentLength() 0
smb.getContentLengthLong() -1
smb.getType() 1

标签: javasambajcifs

解决方案


推荐阅读