`

批量修改文件夹名称(待完成)

    博客分类:
  • J2SE
阅读更多

需求:批量修改文件夹名称

分析:
 设置指定的目录和查找的名称,点搜索,将所有查询到的文件夹路径显示出来,
 确定查询的文件,点全部替换,将符合要求的文件夹名称替换为修改的文件名。

使用知识
 J2SE
  递归
  IO
  
要求
 熟悉相关API使用

示例
 读取一个指定目录
  
 递归读取目录

 

 

import java.io.File;

import junit.framework.TestCase;

/**
 * 了解File API的作用
 * JDK 1.5
 * @author Administrator
 *
 */
public class FileApiTest extends TestCase {

	@Override
	protected void setUp() throws Exception {
		
	}

	@Override
	protected void tearDown() throws Exception {
	}
	
	public void testCanExecute() {
		String pathname = "";
		
		pathname = "c:/";
		File file = new File(pathname);
	}
	
	/**
	 * 判断路径是否存在
	 * 	Y 是
	 *  N 否
	 */
	public void testCanRead() {
		// 定义路径
		String pathname = "";
		
		/** 1.测试一个存在的路径 C盘*/
		pathname = "c:/";
		File file = new File(pathname);			
		System.out.println("路径是否存在=" + (file.canRead()==true ? "Y(是)":"N(否)"));
		
		/** 2.测试一个不存在的路径 Z盘 */
		pathname = "z:/";
		file = new File(pathname);
		System.out.println("路径是否存在=" + (file.canRead()==true ? "Y(是)":"N(否)"));
	}
	
	/**
	 * 判断文件属性可读
	 * Y 可读
	 * N 可读、可写
	 */
	public void testCanWrite() {
		// 定义路径
		String pathname = "";
		
		/** 1.测试:“添加”文件只读属性*/
		pathname = "c:/file_read.txt";
		File file = new File(pathname);			
		System.out.println("文件属性可写=" + (file.canWrite()==true ? "Y(可读、可写)":"N(只读)"));
		
		/** 2.测试:“去掉”文件只读属性*/
		pathname = "c:/file_write.txt";
		file = new File(pathname);
		System.out.println("文件属性可写=" + (file.canWrite()==true ? "Y(可读、可写)":"N(只读)"));
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics