public static void main(String[] args) throws Exception{
String smbJudge = "smb://Administrator:123456@192.168.1.2/bbb/";
String localPath = "D:\\zwh";
readFromSmb(smbJudge,localPath);
}
public static File readFromSmb(String smbJudge, String localPath) {
File localfile = null;
InputStream bis = null;
OutputStream bos = null;
try {
SmbFile rmifile1 = new SmbFile(smbJudge);
SmbFile[] smbFiles = rmifile1.listFiles();
for(SmbFile rmifile : smbFiles ) {
String filename = rmifile.getName();
bis = new BufferedInputStream(new SmbFileInputStream(rmifile));
localfile = new File(localPath + File.separator + filename);
bos = new BufferedOutputStream(new FileOutputStream(localfile));
int length = rmifile.getContentLength();
byte[] buffer = new byte[length];
bis.read(buffer);
bos.write(buffer);
bos.flush();
}
} catch (Exception e) {
System.out.println(e.getMessage());
}finally{
try{
bos.close();
bis.close();
}catch(IOException e){
e.printStackTrace();
}
}
return localfile;
}