拷贝一个目录或者文件到指定路径下
2016-03-23 12:08
423 查看
/** * 拷贝一个目录或者文件到指定路径下 * * @param source * @param target */ public static void copy(File source, File target) { File tarpath = new File(target, source.getName()); if (source.isDirectory()) { tarpath.mkdir(); File[] dir = source.listFiles(); for (int i = 0; i < dir.length; i++) { copy(dir[i], tarpath); } } else { try { InputStream is = new FileInputStream(source); OutputStream os = new FileOutputStream(tarpath); byte[] buf = new byte[1024]; int len = 0; while ((len = is.read(buf)) != -1) { os.write(buf, 0, len); } is.close(); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- android PendingIntent
- js中:Date.utc()方法与getTime()方法返回值不相等的原因
- 判断字符是否属于中文
- swift的一些常见用法
- 正规表达式总结
- 利用runtime将json自动生成model,支持NSArray
- Elasticsearch For Apache Hadoop (ES-Hadoop)最新介绍
- Jena学习
- Day4.3--Android高级UI控件之ProgressBar的使用
- JavaAgent(转载)
- 更改Linux时区的两种方法
- 仪表盘 hostmap 新玩法让运维工作越玩越 high
- 通过React Native动态更新iOS应用
- 关于女生学编程的学习方法
- Protobuffer和json 简单对比(java语言)
- 2016.3.23
- Nginx多站点配置
- Nginx的 UDP 负载均衡
- view的位置参数:
- 仪表盘 hostmap 新玩法让运维工作越玩越 high