Java实现的文件Copy例子
生活随笔
收集整理的這篇文章主要介紹了
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();?
????}?
} 運行結果顯示沒問題:)
本文轉自 leizhimin 51CTO博客,原文鏈接:http://blog.51cto.com/lavasoft/62166,如需轉載請自行聯系原作者
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();?
????}?
} 運行結果顯示沒問題:)
本文轉自 leizhimin 51CTO博客,原文鏈接:http://blog.51cto.com/lavasoft/62166,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的Java实现的文件Copy例子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring4 MVC json问题(4
- 下一篇: 输出值(4)输出值的应用