jcifs已近到了1.3.14版本了,但其中的smbafile还是有些不方便的地方。
其一、不能像java.io.File那样基于parent目录构造新文件。
导致应用代码结构复杂,不好阅读,同时。
其二、每次构造文件都要重新认证,太繁烦。
为此,增加了也smbfile的厂类,以客户上述2个缺点。
package jcifs.smb;
import jcifs.smb.SmbFile;
public class SmbFileFactory {
public static SmbFile get(String url,String connstr) throws Exception
{
return new SmbFile(url,new jcifs.smb.NtlmPasswordAuthentication(connstr));
}
public static SmbFile get(SmbFile parent,String sub) throws Exception
{
return new SmbFile(parent.getPath()+"/"+sub,new SmbFileWraper(parent).getAuth());
}
}
class SmbFileWraper {
SmbFile f;
public SmbFileWraper(SmbFile f1) throws Exception
{
f=f1;
}
public NtlmPasswordAuthentication getAuth()
{
return f.auth;
}
}