This is supposed to be simple, but I can't get it - "Write a program that searches for a particular file name in a given directory." I've found a few examples of a hardcoded filename and directory, but I need both the dir and file name to be as entered by the user.
public static void main(String[] args) {
String fileName = args[0]; // For the filename declaration
String directory;
boolean found;
File dir = new File(directory);
File[] matchingFiles = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String fileName) {
return true;
}
});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…