Java实现的文件Copy例子
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://lavasoft.blog.51cto.com/62575/62166 |
Java实现的文件Copy例子
这个例子是为一个文件系统管理用的,很粗糙,但能处理过程完整,改造一下可以做成一个copyFile方法。
package com.topsoft.icisrpt; import java.io.*; /** * 文件拷贝实现 * 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(); } } 运行结果显示没问题:) 本文出自 “熔 岩” 博客,请务必保留此出处http://lavasoft.blog.51cto.com/62575/62166 本文出自 51CTO.COM技术博客 |



leizhimin
博客统计信息
热门文章
最新评论
友情链接