判断文件是否存在
Android SDK提供了方便的同步接口以检测Bucket中是否存在指定的文件。
以下代码用于判断指定文件是否存在:
try {
if (oss.doesObjectExist("<bucketName>", "<objectKey>")) {
Log.d("doesObjectExist", "object exist.");
} else {
Log.d("doesObjectExist", "object does not exist.");
}
} catch (ClientException e) {
// 本地异常如网络异常等
e.printStackTrace();
} catch (ServiceException e) {
// 服务异常
Log.e("ErrorCode", e.getErrorCode());
Log.e("RequestId", e.getRequestId());
Log.e("HostId", e.getHostId());
Log.e("RawMessage", e.getRawMessage());
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
评论