Atitit.跨语言 文件夹与文件的io操作集合 草案
Atitit.跨语言 文件夹与文件的io操作集合 草案
2. PS: apache commons-io包,FileUtils有相关的方法,IOUtils一般是拷贝文件。1
1. Jdk原生的太难用了。。
2. PS: apache commons-io包,FileUtils有相关的方法,IOUtils一般是拷贝文件。
删除目录结构 FileUtils.deleteDirectory(dest);
递归复制目录及文件 FileUtils.copyDirectory(src, dest);
作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://www.cnblogs.com/attilax/
package aaaAddr;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class copyDirTest {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileUtils.copyDirectory(new File("c:\\00"), new File("c:\\00Copy"));
System.out.println("--f");
}
}
Detail use
1. /**
2. * 复制一个目录及其子目录、文件到另外一个目录
3. * @param src
4. * @param dest
5. * @throws IOException
6. */
package aaaAddr;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import org.apache.commons.io.FileUtils;
import com.attilax.io.filex;
public class copyDirTest {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FutureTask<Object> task=new FutureTask<Object>( new Callable () {
@Override
public Object call() throws Exception {
while(true)
{
String pathname = "c:\\11Copy"+filex.getUUidName();
System.out.println(pathname);
FileUtils.copyDirectory(new File("c:\\11"), new File(pathname));
System.out.println("--f");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//return null;
}
});
new Thread(task).start();
}
}
3. Java raw
7. private void copyFolder(File src, File dest) throws IOException {
8. if (src.isDirectory()) {
9. if (!dest.exists()) {
10. dest.mkdir();
11. }
12. String files[] = src.list();
13. for (String file : files) {
14. File srcFile = new File(src, file);
15. File destFile = new File(dest, file);
16. // 递归复制
17. copyFolder(srcFile, destFile);
18. }
19. } else {
20. InputStream in = new FileInputStream(src);
21. OutputStream out = new FileOutputStream(dest);
22.
23. byte[] buffer = new byte[1024];
24.
25. int length;
26.
27. while ((length = in.read(buffer)) > 0) {
28. out.write(buffer, 0, length);
29. }
30. in.close();
31. out.close();
32. }
33. }
4. 获取磁盘分区列表 驱动器列表
/**
* {
"path": "C:\\"
}
{
"path": "D:\\"
}
{
"path": "E:\\"
}
{
"path": "F:\\"
}
{
"path": "Z:\\"
}
* @param args
*/
public static void main(String[] args) {
//FileChangeObserver
File[] roots = File.listRoots();// 获取磁盘分区列表
for (File file : roots) {
System.out.println(AtiJson.toJson(file));
}
}
}
5. ref
java拷贝目录及其子目录、文件,到另外一个目录 - 一切为了程序 - 博客频道 - CSDN.NET.htm
相关文章
- Linux修改某一个文件VI命令集合
- SpringMVC基础-09-文件上传(单文件、多文件上传)
- C# ini文件操作【源码下载】
- C#目录文件复制、创建操作
- 反射方式,获取出集合ArrayList类的class文件对象
- java复制文件的4种方式
- golang操作gitlab API:获取某个group下的所有仓库并写入文件 && 解决gitpab限制单次查询100条的限制
- ArcGIS Engine开发之旅07---文件地理数据库、个人地理数据库和 ArcSDE 地理数据库中的栅格存储加以比较 、打开栅格数据
- Atitit 文件读取规范 目录 1.1. 以fgetss取代fgets读取一行并过滤掉 HTML 和 PHP 标记。1 1.2. 3. 以二进制读取 fread取代fgets1 1.3. 4.
- Atitit 数据结构与常见文件元数据结构 目录 1. 分类 内部数据结构与外部存储数据结构1 2. 编程语言内部数据结构 (堆栈 树 图等1 2.1. 数据结构 (集合,列表,tree,map
- Atitit.跨语言 文件夹与文件的io操作集合 草案
- 已解决urllib.request.urlretrieve下载文件报错403
- c# - Document编辑office的doc或者docx文件表格指定格子内容并保存-自定义工具
- mongodb底层存储和索引原理——本质是文档数据库,无表设计,同时wiredTiger存储引擎支持文档级别的锁,MMAPv1引擎基于mmap,二级索引(二级是文档的存储位置信息『文件id + 文件内offset 』)
- 集合Map多对多映射(使用xml文件)
- 集合映射中的映射包(使用xml文件)