maven坐标地址
<dependency> <groupId>com.upyun</groupId> <artifactId>java-sdk</artifactId> <version>4.2.3</version> </dependency>
上代码
// 获取文件流hash InputStream inputStream = file.getInputStream(); String fileHash = DigestUtils.md5DigestAsHex(inputStream).toLowerCase(); // 初始化sdk RestManager manager = new RestManager("image-learn-app-avatar", "a392223903", "kqoyJ4kp37IXdDzzqCYHdn3m8ty6q0pxnzvhx1"); manager.setTimeout(60); // 根据hash生成二级目录 String filePath1 = fileHash.substring(0, 2); String filePath2 = fileHash.substring(2, 4); // 创建所需的文件二级目录 String path = File.separator + app + File.separator + filePath1 + File.separator + filePath2 + File.separator; try { System.out.println(path); Response result = manager.mkDir(path); if (!result.isSuccessful()) { throw new BusinessException("创建目录失败,错误码" + result.code()); } } catch (UpException e) { throw new BusinessException("创建目录失败:" + e.getMessage()); } // 填充完整文件名称 String fillName = fileHash + "." + getExtensionByContentType(file.getContentType()); String fillPath = path + File.separator + fillName; // 上传文件 Map<String, String> params = new HashMap<String, String>(); try (Response result = manager.writeFile(fillPath, file.getInputStream(), params)) { if (!result.isSuccessful()) { throw new BusinessException("上传文件失败,错误码" + result.code()); } } catch (UpException e) { throw new BusinessException("上传文件失败:" + e.getMessage()); }
public class test { public static void main(String[] args) { &...
java一个类可以有多个构造方法,根据传参类型和个数来匹配执行哪个构造方法。public class Member { public Member(){  ...
(1).创建数组double[] myList = new double[size]; //推荐创建方式 double myList[] = new double[size];  ...
System.out.println("当前时间戳(秒): " + System.currentTimeMillis()/1000); System.out.println("当前时间戳(毫秒): " +&nb...
pattern表示正则表达式,接收正则表达式作为参数例子:String content = "my name is gaojiufeng"; String pattern = "....
java正则表达式的捕获组捕获组可以将匹配到的结果根据正则中的括号进行分组,这里变量我加了$符,php转java的坏习惯,懒得改了,能跑就行// 匹配字符串 String $line = "gaojiufeng 1994! ok?...