public static void main(String[] args) {
String json = "[
"05605344.jpg",
"472873996.jpg",
"488081532.jpg",
"503827755.jpg",
"505400883.jpg",
"545850476.jpg",
"548509081.jpg",
"548509082.jpg",
"642542204.jpg",
"T110148610.jpg"
]";
JSONArray array = JSONArray.parseArray(json );
String afterPath = "D:\\after";
for (Object fileName : array) {
String path = "D:\\before";
String oldPath = path+"\\"+fileName;
String newPath = afterPath+"\\"+fileName;
try {
File oldFile = new File(oldPath);
int byteread = 0;
int bytesum = 0;
if (oldFile.exists()) {
InputStream inStream = new FileInputStream(oldPath);
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread;
fs.write(buffer, 0, byteread);
}
inStream.close();
}
} catch (Exception e) {
System.out.println("複製單個文件操作出錯");
e.printStackTrace();
}
}
}