java从文件[]文件到目录
我对该代码有一个问题:
public class Files {
public static void main(String[] args) throws IOException {
// filter files AAA.txt and BBB.txt from another's
File f = new File("d:\\dir"); // current directory
File f1 = new File("d:\\dir1\\");
FilenameFilter textFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.startsWith("A") && name.endsWith(".TXT")) {
//System.out.println(name);
return true;
}
else if (name.startsWith("B") && name.endsWith(".TXT")) {
//System.out.println(name);
return true;
}
else {
//System.out.println(name);
return false;
}
}
};
File[] files = f.listFiles(textFilter);
for (File file : files) {
if (file.getName().startsWith("A") ) {
//here save file to d:\\folder1\\
}
}
}
}
在示例AAA中,如何使用特定名称保存文件。txt到文件夹1和BBB。txt到文件夹2。谢谢你的例子
# 1 楼答案
来自Java 7的Files类:
使用move(Path source, Path target, CopyOption... options)