File类的操作
来源:互联网 发布:mac 多因素方差分析 编辑:程序博客网 时间:2024/06/06 07:06
public class TestFile {
//遍历浏览文件
@Test
public void scanFile() {
System.out.println("============");
String path = "/".trim();
File file = new File("H:\\");
File[] files = file.listFiles();
for (File current : files) {
System.out.println("--" + current.getName());
if (current.isDirectory()) {
File getFile = new File(current.getAbsoluteFile().toString());
if (getFile.listFiles() != null) {
File[] files2 = getFile.listFiles();
for (File current2 : files2) {
System.out.println("------------" + current2.getName());
}
}
}
}
}
@Test
public void testFile2() {
System.out.println("============");
String path = "d:\\".trim();
File file = new File(path);
String[] files = file.list();
for (String current : files) {
System.out.println("--" + current);
}
}
@Test
public void testFile3() {
System.out.println("============");
String path = "H:\\".trim();
File file = new File(path);
File[] files = file.listFiles();
for (File current : files) {
System.out.println("--" + current.getAbsolutePath().toString());
System.out.println("--" + current.getParent());
}
}
//创建文件
@Test
public void makeFile() {
System.out.println("============");
String path = "H:\\abc.txt".trim();
File file = new File(path);
System.out.println(file.getAbsolutePath());
if (!file.exists()) {
boolean result = file.mkdirs();
if (result) {
System.out.println("文件创建成功");
} else {
System.out.println("文件创建失败");
}
} else {
System.out.println("文件已经存在");
}
}
//写入文件
@Test
public void writeFile() {
try {
FileWriter fileWriter = new FileWriter("h:\\ceshi.txt".trim(), true);
int[] a = new int[] { 111111, 222222 };
for (int i = 0; i < a.length; i++) {
fileWriter.write(String.valueOf(a[i]) + "");
}
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- File的操作类
- File类的操作
- File类的基本操作
- File类的基本操作
- C# File类的操作
- File类文件的操作
- 操作文件的类-----File
- C# File类的操作
- File操作 - File类/方法
- 操作文件的类File类
- C++的File类文件操作
- C++的File类文件操作
- File 类的字节流操作
- C++的File类文件操作
- C++的File类文件操作
- C++的File类文件操作
- java中File类的相关操作
- java File类的基本操作
- 华为荣耀是待机之王、性能之王、分享之王,我们更希望他是平民之王
- mysql的默认用户名和密码的什么?
- 107个常用Javascript语句
- 数据表格datagrid
- 子类继承父类的实例化顺序
- File类的操作
- 我的第十六个C++上机报告(求一元二次方程的根)
- SQLite的多线程应用与iOS开发
- Java EE项目中的异常处理 (实在写的太好了,导致我非法转载!!!)
- 半边天最新推荐伤感日志发布:寂寞,在指尖滴落
- ASP.NET 页面添加用户控件
- JAVA使用JNI调用C/C++动态库
- 不容错过的精选免费jQuery UI主题大荟萃
- UBI - 标记坏块