拷贝文件夹联系
来源:互联网 发布:日本读研 知乎 编辑:程序博客网 时间:2024/06/07 02:41
以下是我写的copy文件夹的练习:
import java.io.*;import java.util.*;import java.io.*;public class IO{public static void main(String[] args) throws IOException{CopyDirectory.copy("C:\\JAVA_shine","E:");}}class CopyDirectory{public static void copy(String sour, String tar) throws IOException{String[] tempstrs = sour.split("\\\\");String newsour = "\\"+sour;if(tempstrs[0].equals("C:")||tempstrs[0].equals("D:")||tempstrs[0].equals("E:")||tempstrs[0].equals("F:")){newsour = sour;tempstrs = Arrays.copyOfRange(tempstrs, 1, tempstrs.length);StringBuilder strb = new StringBuilder();for(String s : tempstrs){strb.append("\\");strb.append(s);}newsour = new String(strb);}File file = new File(sour);if(file.isDirectory()){System.out.println("这是一个目录:"+sour);File newfile = new File(tar+newsour);System.out.println(newfile.mkdirs());String[] strs = file.list();for(String str : strs){copy(sour+"\\"+str,tar);}}else{System.out.println(sour+"-----------"+tar+newsour);CopyFile.copy(sour,tar+newsour);}}}class CopyFile{public static void copy(String sour, String tar) throws IOException{byte[] bytes = new byte[1024*1024];FileInputStream filein = new FileInputStream(sour);FileOutputStream fileout = new FileOutputStream(tar);while(filein.read(bytes)!=-1){bytes = Arrays.copyOf(bytes,(int)(bytes.length*1.5));}int i = bytes.length-1;for(; i>=0; i--){if(bytes[i] != 0)break;}if(i == -1)i = 0;bytes = Arrays.copyOf(bytes, i);fileout.write(bytes);filein.close();fileout.close();}}
0 0
- 拷贝文件夹联系
- 拷贝文件夹
- 拷贝文件夹
- 拷贝文件夹
- 文件夹拷贝
- 拷贝文件夹
- 文件夹拷贝
- 拷贝文件夹 删除文件夹
- 文件夹、文件夹内容拷贝
- VB拷贝文件,拷贝文件夹
- 服务器端文件夹拷贝
- 拷贝复制文件夹
- linux的 拷贝文件夹
- Ant拷贝文件夹
- Netinstall 拷贝驱动文件夹
- vc 递归拷贝文件夹
- inno setup拷贝文件夹
- Win32拷贝文件夹
- Android的集成新浪微博第三方登录
- 关于ios7上无法计算UITextView的contentSize.height的解决方法
- 表单的相关事件及特效
- google-gson使用解析
- 淘宝网的技术发展史(一)——个人网站时代
- 拷贝文件夹联系
- Redis的内部数据结构
- Xcode5下编译amr和speex库
- 测试驱动开发系列之七--监视产品代码
- 淘宝网的技术发展史(二) ——Oracle替换MySQL
- Sapera LT 7.2 在VS2010下的配置
- Android -- setTag的妙用和The key must be an application-specific resource id 异常
- 九度1081解题报告
- RAC安装时,报The specified nodes are not clusterable 的解决方法