try {
// smb://userName:passWord@host/path/folderName
smbFile = new SmbFile(remoteUrl + folderName);
if (!smbFile.exists()) {
smbFile.mkdir();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (SmbException e) {
e.printStackTrace();
}
}
四、上传文件
/**
-
上传文件
-
@param remoteUrl
-
@param shareFolderPath
-
@param localFilePath
-
@param fileName
*/
public static void uploadFileToSharedFolder(String remoteUrl, String shareFolderPath, String localFilePath, String fileName) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
File localFile = new File(localFilePath);
inputStream = new FileInputStream(localFile);
// smb://userName:passWord@host/path/shareFolderPath/fileName
SmbFile smbFile = new SmbFile(remoteUrl + shareFolderPath + “/” + fileName);
smbFile.connect();
outputStream = new SmbFileOutputStream(smbFile);
byte[] buffer = new byte[4096];
int len = 0; // 读取长度
while ((len = inputStream.read(buffer, 0, buffer.length)) != -1) {
outputStream.write(buffer, 0, len);
}
// 刷新缓冲的输出流
outputStream.flush