如何实现Java中通用的文件复制方法?
- 内容介绍
- 文章标签
- 相关推荐
本文共计93个文字,预计阅读时间需要1分钟。
javapublic static void copyFile(File fromFile, File toFile) throws IOException { FileInputStream ins=new FileInputStream(fromFile); FileOutputStream out=new FileOutputStream(toFile); byte[] b=new byte[1024]; int n=0; while ((n=ins.read(b)) !=-1) { out.write(b, 0, n); } ins.close(); out.close();}
public static void copyFile(File fromFile,File toFile) throws IOException{ FileInputStream ins = new FileInputStream(fromFile); FileOutputStream out = new FileOutputStream(toFile); byte[] b = new byte[1024]; int n=0; while((n=ins.read(b))!=-1){ out.write(b, 0, b.length); } ins.close(); out.close(); }
本文共计93个文字,预计阅读时间需要1分钟。
javapublic static void copyFile(File fromFile, File toFile) throws IOException { FileInputStream ins=new FileInputStream(fromFile); FileOutputStream out=new FileOutputStream(toFile); byte[] b=new byte[1024]; int n=0; while ((n=ins.read(b)) !=-1) { out.write(b, 0, n); } ins.close(); out.close();}
public static void copyFile(File fromFile,File toFile) throws IOException{ FileInputStream ins = new FileInputStream(fromFile); FileOutputStream out = new FileOutputStream(toFile); byte[] b = new byte[1024]; int n=0; while((n=ins.read(b))!=-1){ out.write(b, 0, b.length); } ins.close(); out.close(); }

