JAVA#BufferedIn&OutputStream札記
阿新 • • 發佈:2019-01-11
public class BufferTest { @Test public void kkkkbb(){ String s1="C:\\Users\\Administrator\\Desktop\\1.pic_hd.jpg"; String s2="C:\\Users\\Administrator\\Desktop\\kobebean.jpg"; kkkooob(s1,s2); } public void kkkooob(String str1,String str2){ try { File file1 = new File(str1); File file2 = new File(str2); FileInputStream fis = new FileInputStream(file1); FileOutputStream fos = new FileOutputStream(file2); BufferedInputStream bis = new BufferedInputStream(fis); BufferedOutputStream bos = new BufferedOutputStream(fos); byte[] b = new byte[10]; int length; while ((length = bis.read(b)) != -1) { bos.write(b, 0, length); bos.flush(); } bos.close(); bis.close(); }catch (Exception e){ e.printStackTrace(); } } }