Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92000
  • 博文数量: 81
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-20 14:50
文章分类

全部博文(81)

文章存档

2014年(21)

2013年(60)

我的朋友

分类: Java

2013-12-26 13:23:10

  Java实现的文件Copy例子

  这个例子是为一个文件系统管理用的,很粗糙,但能处理过程完整,改造一下可以做成一个copyFile方法。

  package com.topsoft.icisrpt;

  import java.io.*;

  /**sdudd1226

  * 文件拷贝实现

  * File: FileCopyTest.java

  * User: leizhimin

  * Date: 2008-2-15 11:43:54

  */

  public class FileCopyTest {

  public static void main(String args[]) throws IOException {

  FileCopyTest t=new FileCopyTest();

  t.testCopy();

  }

  public void testCopy() throws IOException {

  FileInputStream fin = new FileInputStream(new File("D:\\projectsCC\\leizhimin_main_TopIcis_V1.6\\IcisReport\\src\\com\\topsoft\\icisrpt\\xslFiles\\R05_QD01.xsl"));

  FileOutputStream fout = new FileOutputStream(new File("D:\\projectsCC\\leizhimin_main_TopIcis_V1.6\\IcisReport\\src\\com\\topsoft\\icisrpt\\xslFiles\\R05_QD012.xsl"));

  int bytesRead;

  byte[] buf = new byte[4 * 1024]; // 4K

  while ((bytesRead = fin.read(buf)) != -1) {

  fout.write(buf, 0, bytesRead);

  }

  fout.flush();

  fout.close();

  fin.close();

  }

  }

  运行结果显示没问题:)

阅读(157) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~