Java实现的文件Copy例子
生活随笔
收集整理的這篇文章主要介紹了
Java实现的文件Copy例子
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這個(gè)例子是為一個(gè)文件系統(tǒng)管理用的,很粗糙,但能處理過(guò)程完整,改造一下可以做成一個(gè)copyFile方法。 package?com.topsoft.icisrpt;?
import?java.io.*;?
/**?
* 文件拷貝實(shí)現(xiàn)?
* 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();?
????}?
} 運(yùn)行結(jié)果顯示沒(méi)問(wèn)題:)
本文轉(zhuǎn)自 leizhimin 51CTO博客,原文鏈接:http://blog.51cto.com/lavasoft/62166,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
import?java.io.*;?
/**?
* 文件拷貝實(shí)現(xiàn)?
* 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();?
????}?
} 運(yùn)行結(jié)果顯示沒(méi)問(wèn)題:)
本文轉(zhuǎn)自 leizhimin 51CTO博客,原文鏈接:http://blog.51cto.com/lavasoft/62166,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的Java实现的文件Copy例子的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring4 MVC json问题(4
- 下一篇: Java SE 6之GUI:让界面更加绚