今天用jcifs访问xp的共享文件,老是报异常: jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
public class eeee {
public static void main(String[] args) {
try {
SmbFile smbFile = new SmbFile(
"smb://account:password@computerIp/111/aaa.txt");
// 通过 smbFile.isDirectory();isFile()可以判断smbFile是文件还是文件夹
int length = 512;//smbFile.getContentLength();// 得到文件的大小
byte buffer[] = new byte[length];
SmbFileInputStream in = new SmbFileInputStream(smbFile); // 建立smb文件输入流
while ((in.read(buffer)) != -1) {
System.out.write(buffer);
//System.out.println(buffer.length);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
解决的方法是,配置共享机器的共享方式为高级共享
工具->文件夹选项->查看-> 去掉【简单文件夹共享(推荐)】的选择