现在想要生成一份1-50张,按照1.jpg,2.jpg,3.jpg,4.jpg这样顺序的图片,该怎样生成?
public class CopyJpg { public static void main(String[] args) throws IOException { //根据数据源创建字节输入流对象 ArrayList<String> array = new ArrayList<String>(); for (int i = 1; i <= 50; i++) { int arr = i; String s1 = "files\\" + arr + ".jpg"; array.add(s1); } System.out.println(array); FileInputStream fis = new FileInputStream("C:\\Users\\17517\\Pictures\\1.jpg"); for(int i=0;i<array.size();i++){ String s = array.get(i); FileOutputStream fos = new FileOutputStream(s); byte[] bys = new byte[1024]; int len; while ((len=fis.read(bys))!=-1) { fos.write(bys,0,len); } fos.close(); } fis.close(); }}
效果: