Java 文件的拷贝
生活随笔
收集整理的這篇文章主要介紹了
Java 文件的拷贝
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一:上碼
package com.wyj.two;import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;/*** 文件得拷貝:文件輸入流 和輸出流* @author 86155**/ public class Demo6_文件得拷貝 {public static void main(String[] args) {File src = new File("text.txt");//源頭File dext = new File("dext.txt");//目的地InputStream is = null;OutputStream os = null;try{is = new FileInputStream(src);os = new FileOutputStream(dext);byte flush[] =new byte[1024];int len = -1;while((len = is.read(flush)) != -1 ){String str = new String(flush,0,len);//System.out.println(str);byte date[] = str.getBytes();//字符串 ---->字節(jié)數(shù)組(編碼)os.write(date, 0,date.length);os.flush();}}catch(FileNotFoundException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}finally{//釋放資源 分別關(guān)閉 先打開(kāi)的后關(guān)閉try{if(os != null ){os.close();}}catch(IOException e){e.printStackTrace();}try{if(is != null){is.close();}}catch(IOException e){e.printStackTrace();}}} }總結(jié)
以上是生活随笔為你收集整理的Java 文件的拷贝的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 诺氟沙星胶囊治拉肚子吗
- 下一篇: 什么是固定义齿?