本帖最后由 寇龙飞 于 2012-8-29 01:25 编辑
- public static void copyFile(String from, String dest) throws Exception {
-
- File ff = new File(from);//目标文件
- File ft = new File(dest);//目的文件
-
- FileInputStream fis = new FileInputStream(ff);
- FileOutputStream fos = new FileOutputStream(ft);
-
- BufferedInputStream bufis =new BufferedInputStream(fis);
- BufferedOutputStream bufos =new BufferedOutputStream(fos);
-
- byte[] buf = new byte[1024*4];
- int count = 0;
- while((count=bufis.read(buf, 0, buf.length))!=-1) {
- bufos.write(buf, 0, count);
- //bufos.flush();//需不需要刷新?
复制代码 这是我一个复制文件程序的部分代码。看代码注视部分。求解。
之前贴的代码while循环都不完整,失误,重贴个。- BufferedInputStream bufis =new BufferedInputStream(fis);
- BufferedOutputStream bufos =new BufferedOutputStream(fos);
-
- byte[] buf = new byte[1024*4];
- int count = 0;
- while((count=bufis.read(buf, 0, buf.length))!=-1) {
- bufos.write(buf, 0, count);
- //bufos.flush();//需不需要刷新?
- }
- bufis.close();
- bufos.close();
复制代码 |