java - 查找 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
解决方案
推荐阅读
- discord - Bot 用户计数返回:NaN
- karate - 如何忽略 json 中的某些字段以在空手道测试中进行比较
- java - Android Recyclerview 小部件的替代品
- python - 获取Django中序列化程序保存的对象的最后插入ID
- vb.net - 数学表达式解析:当 + 后跟 - 时输出不正确
- aws-lambda - 如何使用 Terraform 获取 AWS Lambda ARN?
- python - Pydantic 设置属性与默认函数
- arrays - 使用带有数组参数的函数指针的分段错误
- javascript - 如何在 JavaScript 中将 jpeg 转换为渐进式图像?
- google-apps-script - 将脚本中的粘贴范围限制为 3 列