一:确认思路
1.查看官方文档的批量操作说明
二:确认具体步骤
1.查看官方文档后可以确认几个要点
- 删除的图片以及元数据文件要放在oss同一路径下
- 元数据的格式如下主要有两个字段OperationType、ProductId
2.元数据生成步骤
1.将实例数据元信息导出,格式如下
{"CategoryId":"88888888","CustomContent":"","PicName":"222","ProductId":"111","IntAttr":"","StrAttr":""}
{"CategoryId":"88888888","CustomContent":"","PicName":"222","ProductId":"222","IntAttr":"","StrAttr":""}
2.将导出的元信息内容提取出来,生成如下元数据
{"OperationType":"DELETE","ProductId":"111"}
{"OperationType":"DELETE","ProductId":"222"}
3.添加依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
4.JavaCode
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.io.*;
/**
* JsonTest
*
* @Author Tan
* @Date: 2021/2/26 10:38
* @Version 1.0
*/
public class Json {
public static void main(String[] args) {
try {
File jsonReadFile = new File("C:\\Users\\cnc\\Desktop\\test.txt");
FileReader fileReader = new FileReader(jsonReadFile);
BufferedReader sb = new BufferedReader(fileReader);
String line = null;
JSONObject json = new JSONObject(16,true);
PrintWriter out = new PrintWriter(new FileWriter("C:\\Users\\cnc\\Desktop\\increment.meta"));
while ((line = sb.readLine()) != null) {
JSONObject jsonObject = JSON.parseObject(line);
System.out.println(jsonObject.getString("ProductId"));
json.put("OperationType","DELETE");
json.put("ProductId",jsonObject.getString("ProductId"));
out.write(json.toString()+"\t\n");
System.out.println("输出完成");
}
fileReader.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
4.运行结果