public void copyFile(String oldPath, String newPath) throws IOException {
(new File(newPath)).mkdirs();
String[] file = new File(oldPath).list();
File fileTemp = null;
String separator = File.separator;
for (int i = 0; i < file.length; i++) {
if (oldPath.endsWith(separator)) {
fileTemp = new File(oldPath + file[i]);
} else {
fileTemp = new File(oldPath + separator + file[i]);
}
if (fileTemp.isFile()) {
FileInputStream fis = new FileInputStream(fileTemp);
if (file[i].endsWith(".txt")) {
fileTemp = new File(oldPath + separator + file[i].substring(0, file[i].length() - 4) + ".sql");
}
FileOutputStream fos = new FileOutputStream(newPath + "/" + fileTemp.getName());
byte[] b = new byte[1024 * 5];
int len;
while ((len = fis.read(b)) != -1) {
fos.write(b, 0, len);
}
fos.flush();
fos.close();
fis.close();
}
if (fileTemp.isDirectory()) {
this.copyFile(oldPath + "/" + file[i], newPath + "/" + file[i]);
}
}
}

  

已知源目录路径sourceFilePath,此目录下还有多级子目录和多个文本文件(*.txt)。尝试编写一个方法,将此目录下所有的文件拷贝至另一个目录targetFilePath,并其中的文本文件修改成SQL文件(*.SQL)。的更多相关文章

  1. Java已知图片路径下载图片到本地

    public static void main(String[] args) { FileOutputStream fos = null; BufferedInputStream bis = null ...

  2. [BAT] 以当前时间为名创建文件夹,将本地文件夹里的文件拷贝到远程共享目录,而且保证本地和Jenkins上运行都成功

    @echo off rem connect to szotpc801 net use * /del /yes NET USE X: \\10.66.234.95\d$ Autotest123 /use ...

  3. linux把某个文件拷贝到不同的目录下面

    find -name '7*' -type d|xargs -n 1 cp PBClassname.properties

  4. Oracle中将密码有效期由默认的180天修改成“无限制”

    将密码有效期由默认的180天修改成“无限制”: 在系统管理员下执行如下语句即可 ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED 修改之 ...

  5. 已知问题汇总 (2013-11-30) - QQ空间, EXTJS

    目前发现两个已知问题暂时无法得到解决: 1. QQ空间问题. 打开页面 http://user.qzone.qq.com/822994792/311, 点击 "xxx人赞" 这个链 ...

  6. POJ3304:Segments (几何:求一条直线与已知线段都有交点)

    Given n segments in the two dimensional space, write a program, which determines if there exists a l ...

  7. java中把文件拷贝到指定目录下最简单几种方法

    java中把文件拷贝到指定目录下最简单几种方法   String savePath = "D:/file";// 文件保存到d盘的file目录下 File savefile = n ...

  8. 用find命令删除某目录下及所有子目录中某类型的特定文件

    当前目录下含有多级子目录,并且每一个子目录下都含有多个文件,如何删除当前目录及所有子目录下特定类型的文件,比如:*.pyc(所有文件名以“*.pyc”结尾的文件): 可以使用find命令,将当前目录下 ...

  9. Golang调用windows下的dll动态库中的函数 Golang 编译成 DLL 文件

    Golang调用windows下的dll动态库中的函数 package main import ( "fmt" "syscall" "time&quo ...

随机推荐

  1. 你不知道的css各类布局(二)之流体布局、液体布局、栅格布局

    流体布局 什么是流 在谈论流体布局之前我们需要知道一件事情就是何为“流”,所谓“流”就是“文档流”,是css中的一种基本定位和布局 概念 流体布局(Liquid/Fluid Layout)指的是利用元 ...

  2. 基于SQL Server日志链查看数据库insert/update/delete操作(一)

    在MSSQLServer2008下的语句 不同版本可能语句会有微小差别 SELECT [Slot ID], [Transaction ID], Operation, AllocUnitName, [C ...

  3. app嵌套的vue项目更新后,页面没有更新

    记录下解决过程 1.index.html增加下面meta标签 <meta http-equiv="pragram" content="no-cache"& ...

  4. 使用svn遇到的问题---(在编辑器没有配置svn的前提下)

    日常写代码的过程中新增了文件,一般都是继续文件的书写,写完一部分后提交 新增文件后面经常忘记了add后commit 原来是可以在commit时勾选左下角的 [show unversioned file ...

  5. 销售订单(SO)-API-登记销售订单

    登记销售订单可以在新增订单的时候就登记:并不是去修改 flow_status 为booked,而是赋值action request:就下面两句 l_action_request_tbl(l_actio ...

  6. 几种常用的java 实现反转的方法———reverse

    1.最简单的方法 public static String reverse1(String str) return new StringBuffer(str).reverse().toString() ...

  7. app hellocharts 柱状图

    app里有个告警数量的柱状图,有点小问题,y轴竟然不是整数 这个改起来到是简单 Axis yAxis = new Axis().setHasLines(true).setTextColor(Color ...

  8. Hive的日志操作

    想要看hive的日志,我们查看/home/hadoop/hive/conf/hive-log4j2.properties # list of properties property.hive.log. ...

  9. 移动端h5+vue失焦搜索,ios和android兼容问题

    html部分: <input type="search" :placeholder="placeholder" v-model="searchN ...

  10. Delphi ClearCommError函数