我是 JCIFS 的新手,我正在尝试使用 JCIFS 在受密码保护的共享路径中写入(创建新)文件。下面的代码将为您概述我正在尝试实现它的内容和方式。
String user = "myUserId";
String pass ="myPassword#";
String path = "smb:\\\\<<My Host>>\\Hag\\To GC\\Tester\\test.txt";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("<<My Domain>>",user, pass);
SmbFile smbFile = new SmbFile(path,auth);
SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
smbfos.write("Testing JCFIC".getBytes());
我得到了NullPointerException
一个
SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
Exception in thread "main" java.lang.NullPointerException
at jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java:213)
at jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java:202)
at jcifs.smb.SmbComNTCreateAndX.writeBytesWireFormat(SmbComNTCreateAndX.java:170)
at jcifs.smb.AndXServerMessageBlock.writeAndXWireFormat(AndXServerMessageBlock.java:101)
at jcifs.smb.AndXServerMessageBlock.encode(AndXServerMessageBlock.java:65)
at jcifs.smb.SmbTransport.doSend(SmbTransport.java:439)
at jcifs.util.transport.Transport.sendrecv(Transport.java:67)
at jcifs.smb.SmbTransport.send(SmbTransport.java:655)
at jcifs.smb.SmbSession.send(SmbSession.java:238)
at jcifs.smb.SmbTree.send(SmbTree.java:119)
at jcifs.smb.SmbFile.send(SmbFile.java:775)
at jcifs.smb.SmbFile.open0(SmbFile.java:989)
at jcifs.smb.SmbFile.open(SmbFile.java:1006)
at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:97)
at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:67)
at com.labcorp.efone.utility.Tester.main(Tester.java:35)
执行上述程序时请参见下文。请让我知道我错过了什么,并引导我走向正确的方向。