s- package demo.io;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class IODemo5 {
- /**
- * d:\\EditPlus.zip 到 C:盘
- *
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- File src = new File("d:\\EditPlus.zip");
- FileInputStream fin = null;
- FileOutputStream fos = null;
- fin = new FileInputStream(src);
- fos = new FileOutputStream("c:\\copy_EditPlus.zip");
- // CopyByByte(fin, fos);
- copyByBuf(fin, fos);
- }
- private static void copyByBuf(FileInputStream fin, FileOutputStream fos)
- throws IOException {
- byte[] buf = new byte[1024];
- int len = 0;
- while((len = fin.read(buf))!=-1){
- fos.write(buf,0,len);
- }
- System.out.println("done");
- fin.close();
- fos.close();
- }
- private static void CopyByByte(FileInputStream fin, FileOutputStream fos)
- throws IOException {
- int by = 0;
- while ((by = fin.read()) != -1) {
- fos.write(by);
- }
- fos.flush();// 函数内容为空,调用其实没意思
- System.out.println("done");
- fin.close();
- fos.close();
- }
- }
复制代码
|
|