集册 Java实例教程 使用流复制二进制文件

使用流复制二进制文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

440
使用流复制二进制文件


import java.io.FileInputStream;

import java.io.FileNotFoundException;
/*
 from 时 代 J a v a - N o w J a v a . c o m 
*/

import java.io.FileOutputStream;

import java.io.IOException;


public class Main {


  public static void main(String[] args) {


    String strSourceFile = "C:/Folder/source.dat";

    String strDestinationFile = "C:/Folder/dest.dat";
/** nowjava - 时代Java 提 供 **/

    try {

      FileInputStream fin = new FileInputStream(strSourceFile);

      FileOutputStream fout = new FileOutputStream(strDestinationFile);

      byte[] b = new byte[1024];

      int noOfBytes = 0;

      while ((noOfBytes = fin.read(b)) != -1) {

        fout.write(b, 0, noOfBytes);

      }

      System.out.println("File copied!");

      fin.close();

      fout.close();

    } catch (FileNotFoundException fnf) {

      
展开阅读全文