think in java - IO - file

# what does 'File path = new File(".");' mean?java

project root pathide


# how to see a directory listing?
spa

  1. list(): return String[] code

  2. list(FilenameFilter)orm

class DirFilter implements FilenameFilter {

	private Pattern pattern;
	
	public DirFilter(String regex) {
		pattern = Pattern.compile(regex);
	}
	
	/** my only reason for existence 
	 *  callback
	 *  strategy design pattern
	 * */
	@Override
	public boolean accept(File dir, String name) {
		return pattern.matcher(name).matches();
	}
}


# rename fileget

File old = new File(args[1]), rname = new File(args[2]);
old.renameTo(rname);


# file attributesit

f.getPath();
f.getAbsolutePath()
f.canRead()
f.canWrite()
f.getName()
f.getParent()
f.length()
f.lastModified()
f.isFile()
f.isDirectory()
相關文章
相關標籤/搜索