使用 Sardine 实现webDav文件操作
基于 Sardine 实现对 WebDav 服务的文件上传、下载、删除、重命名、移动等操作
依赖包
<dependency>
<groupId>com.github.lookfirst</groupId>
<artifactId>sardine</artifactId>
<version>5.9</version>
</dependency>
使用类
import com.github.sardine.Sardine;
import com.github.sardine.SardineFactory;
操作例子
上传文件
/**
* 上传文件 <br/>
* 当对应路径对应文件名已经存在,再次上传会覆盖掉原来的文件
* @param filePath 文件的相对路径或者绝对路径均可
* @param inputStream 输入流
* @return 保存后的绝对路径
* @throws IOException io异常
*/
public static String upload(String filePath, InputStream inputStream) throws IOException {
// 如果路径中没有加上webDav的url,则添加上去,返回绝对路径
filePath = CommonUtil.getAbsolutePath(config.getBaseUrl(), filePath);
// 根据用户名、密码初始化Sardine对象
Sardine sardine = SardineFactory.begin(config.getUserName(), config.getPassword());
// 判断目录是否存在
String dirPath = filePath.substring(0, filePath