[AppleScript] 纯文本查看 复制代码 public class Day39_9月点招题一3 {
/**
* @author purity 2016-10-7下午2:50:54
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File dir = getDir("P:\\传智播客\\前期培优班\\27天笔记");
TreeSet<String> ts = new TreeSet<>(new CompareByLen());
TreeSet<String> _ts = toFileNameStoreSet(dir, ts);
for (String file : _ts) {
System.out.println(file);
}
}
public static File getDir(String fileName) {
File dir = new File(fileName);
if (!dir.exists()) {
System.out.println("不存在");
} else if (!dir.isDirectory()) {
System.out.println("不是目录");
}
return dir;
}
public static TreeSet<String> toFileNameStoreSet(File dir, TreeSet<String> ts) {
File[] subFiles = dir.listFiles();
for (File subFile : subFiles) {
if (subFile.isFile() && subFile.getName().endsWith(".java")) {
ts.add(subFile.getName());
} else {
if (subFile.isDirectory())
toFileNameStoreSet(subFile, ts);
}
}
return ts;
}
}
class CompareByLen implements Comparator<String> {
@Override
public int compare(String lhs, String rhs) {
int len = lhs.length() - rhs.length();
return len == 0 ? lhs.compareTo(rhs) : len;
}
}
|