微调
This commit is contained in:
@@ -136,8 +136,9 @@ public class AliYunOssUtils {
|
|||||||
* @return 文件字节流
|
* @return 文件字节流
|
||||||
*/
|
*/
|
||||||
public InputStream downloadStream(String objectName) {
|
public InputStream downloadStream(String objectName) {
|
||||||
try (OSSObject ossObject = ossClient.getObject(ossConfig.getBucket(), objectName);
|
try {
|
||||||
InputStream inputStream = ossObject.getObjectContent()) {
|
OSSObject ossObject = ossClient.getObject(ossConfig.getBucket(), objectName);
|
||||||
|
InputStream inputStream = ossObject.getObjectContent();
|
||||||
return inputStream;
|
return inputStream;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("文件{}下载为字节数组失败", objectName, e);
|
logger.error("文件{}下载为字节数组失败", objectName, e);
|
||||||
@@ -152,10 +153,10 @@ public class AliYunOssUtils {
|
|||||||
* @return 文件字节数组
|
* @return 文件字节数组
|
||||||
*/
|
*/
|
||||||
public byte[] downloadFileToBytes(String objectName) {
|
public byte[] downloadFileToBytes(String objectName) {
|
||||||
try (OSSObject ossObject = ossClient.getObject(ossConfig.getBucket(), objectName);
|
try {
|
||||||
InputStream inputStream = ossObject.getObjectContent();
|
OSSObject ossObject = ossClient.getObject(ossConfig.getBucket(), objectName);
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
InputStream inputStream = ossObject.getObjectContent();
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int len;
|
int len;
|
||||||
while ((len = inputStream.read(buffer)) != -1) {
|
while ((len = inputStream.read(buffer)) != -1) {
|
||||||
@@ -203,17 +204,9 @@ public class AliYunOssUtils {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("查找OSS文件夹 {} 最新文件失败", folderPath, e);
|
logger.error("查找OSS文件夹 {} 最新文件失败", folderPath, e);
|
||||||
throw new RuntimeException("查找最新文件失败:" + folderPath, e);
|
throw new RuntimeException("查找最新文件失败:" + folderPath, e);
|
||||||
}finally {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String latestFileName="latestFileNam.xlsx";
|
|
||||||
|
|
||||||
String s = latestFileName.split(".xlsx")[0];
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* 删除单个文件
|
* 删除单个文件
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user