import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class DemoByte04 { public static void main(String[] args) throws IOException{ //读取目标文件 File filer = new File("D:\123.jpg"); FileInputStream fis = new FileInputStream(filer); //写入目标文件 File filew = new File("Month" + File.separator + "src" + File.separator + "LearnIO" + File.separator + "copy.jpg"); FileOutputStream fos = new FileOutputStream(filew); byte[] bt=new byte[1024];//通常写1024或其整数倍 int len=0; while((len=fis.read(bt))!=-1){ fos.write(bt,0,len);//写入字节的有效长度 } fos.close(); fis.close(); } }