求教 字节流中OutputStream.write()中直接写InputStream.read()和通过int变量过渡一些的区别
学习Java中,看到字节流的时候按照书上的介绍自己写了一段代码,结果运行后保存的文件是错的,
public static void backup(File f01,File f02)throws Exception {// File f01 = new File(sourcePath);// File f02 = new File(path); int temp=0; FileInputStream fis = new FileInputStream(f01); FileOutputStream fos = new FileOutputStream(f02); while(fis.read()!=-1) { fos.write(fis.read()); }
public static void backup(File f01,File f02)throws Exception {// File f01 = new File(sourcePath);// File f02 = new File(path); int temp=0; FileInputStream fis = new FileInputStream(f01); FileOutputStream fos = new FileOutputStream(f02); while((temp=fis.read())!=-1) { fos.write(temp); }
while(fis.read()!=-1) { fos.write(fis.read()); }