---
title: "用java   io读取一个文件，文件格式可能是txt，excel或者其他的"
author: "huwanshan"
date: "2008-12-20T20:33:15Z"
tags: ["C", "C#", "C++", "Excel", "Java"]
slug: "java-io-txt-excel"
draft: false
lastmod: "2008-12-20T20:33:15Z"
id: 298027
url: "https://javabbs.iteye.com/blog/298027"
---

public   static   int   copyFile(String   src,   String   dst)   {   
          try   {   
              int   len   =   0;   
              byte[]   buf   =   new   byte[1024];   
              FileInputStream   fis   =   new   FileInputStream(src);   
              FileOutputStream   fos   =   new   FileOutputStream(dst);   
              while   (   (len   =   fis.read(buf))   !=   -1)   {   
                  fos.write(buf,   0,   len);   
              }   
              fis.close();   
              fos.close();   
          }   
          catch   (IOException   e)   {   
              System.out.println(e);   
              return   -1;   
          }   
          return   0;   
      }   
    
  例子：   
  copyFile("c:\\test\\test.xls","c:\\test\\bkr\\test.xls");




用java   io读取一个文件，文件格式可能是txt，excel或者其他的。   
    
  比如一个xls后缀的excel文件     路径：c:\test\test.xls   
    
  用java   io   读取这个文件后，要把它完整的（包括格式）备份到   c:\test\bkr   目录下面。   
    
 