package java7; import com.sun.org.apache.bcel.internal.generic.NEW; import org.junit.Test; import java.io.*; /** * @author 冀帅 * @date 2020/8/19-11:40 */ public class InOutTest { @Test public void test(){ //1 FileInputStream in = null; FileOutputStream out = null; try { File file = new File("IMG_20200817_113832.jpg"); File file1 = new File("Isa.jpg"); //2 in = new FileInputStream(file); out = new FileOutputStream(file1); //3 byte[] Byte = new byte[1024]; int len; while ((len = in.read(Byte))!=-1){ out.write(Byte,0,len); } } catch (IOException e) { e.printStackTrace(); } finally { //4 try { if (in!=null) in.close(); } catch (IOException e) { e.printStackTrace(); } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }