import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class demo06 { public static void main(String[] args) throws IOException { // 重复操作 for (int i = 2; i < 10; i++) { // 创建字节输入流对象 FileInputStream fis = new FileInputStream("F:\\班委\\2.1学生健康打卡信息表.xlsx"); String filename = "2." + Integer.toString(i) + "学生健康打卡信息表.xlsx"; // 创建字节输出流对象 FileOutputStream fos = new FileOutputStream("F:\\班委" + "\\" + filename); int len = 0; byte[] bytes = new byte[1024]; while((len = fis.read(bytes)) != -1) { fos.write(bytes, 0, len); } // 释放资源 fos.close(); fis.close(); } } }
结果如下: