我尝试使用jcifs库实现将本地文件传输到网络驱动器的功能,但是在命令行上运行程序时,我收到以下异常:
Exception in thread "main" java.lang.NullPointerException
jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java: 202)
要理解错误,我尝试在eclipse上调试代码,并在执行此操作时: NtlmPasswordAuthentication身份验证=新NtlmPasswordAuthentication(“xxxxxx.xx.com”,用户名,密码);
我收到一条说明ClassNotFoundException的异常。但是我在构建路径中有jcifs.jar。
快速谷歌搜索'ntlmpasswordauthentication'classnotfoundexception让我找到了两个线程,但问题相同,但没有解析。
请让我知道如何解决此问题。
谢谢
以下是整个功能,只是在需要的情况下:
private static void TransferFiles()
{
File transfer_files = new File (sourcepath);
File[] files = transfer_files.listFiles();
String username = properties.getProperty("user");
String password = properties.getProperty("password");
String source = sourcepath;
SmbFileOutputStream outputStream = null;
FileInputStream inputStream = null;
SmbFile copyFile = null;
byte[] buffer = new byte[16*1024*1024];
int length = 0;
jcifs.smb.NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("xxxxxxx",username,password);
try
{
copyFile = new SmbFile(destinationpath,authentication);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
try
{
outputStream = new SmbFileOutputStream(copyFile);
}
catch (SmbException | MalformedURLException | UnknownHostException e)
{
e.printStackTrace();
}
try
{
inputStream = new FileInputStream(sourceFile);
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
try
{
while((length = inputStream.read(buffer))>0)
{
outputStream.write(buffer, 0, length);
}
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
inputStream.close();
outputStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}