把指定的文件复制到目标文件夹下

来源:互联网 发布:少儿英语网络课程价格 编辑:程序博客网 时间:2024/04/28 17:04
package what;import java.io.*;public class Example{public void copy() throws IOException{String filePath="E:/编程程序/what/test.txt";     //文件pathString dirPath="E:/编程程序/what复制件";          //目录pathtry(FileInputStream input=new FileInputStream(filePath);FileOutputStream output=new FileOutputStream(dirPath+File.separator+filePath.substring(dirPath.lastIndexOf("/")))){byte[] bbuf=new byte[1024];int hasRead=0;while((hasRead=input.read(bbuf))>0){output.write(bbuf,0,hasRead);}}catch(Exception ioe){ioe.printStackTrace();}}public static void main(String[] args) throws IOException{new Example().copy();}}

0 0
原创粉丝点击