- 字节流读写非文本文件(图片、视频等)
@Test public void test5(){ File srcFile = new File("FLAMING MOUNTAIN.JPG"); File destFile = new File("FLAMING MOUNTAIN1.JPG"); FileInputStream fis = null; FileOutputStream fos = null; try { //字节输入输出流 fis = new FileInputStream(srcFile); fos = new FileOutputStream(destFile); //复制 byte[] buffer = new byte[5]; int len; while ((len = fis.read(buffer)) != -1){ fos.write(buffer, 0, len); } } catch (IOException e) { e.printStackTrace(); } finally { if (fos != null){ try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } if (fis != null){ try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } }