Hi guys,
So I'm doing an assignment right now. One of the tasks is about listing files. It wants you to insert a name, either directory or a certain file, and give you a message with some informations. So I'm trying to finish the part where I enter a directory name, before I do the file part.
So my questions:
When I enter a directory/folder name, it wants me output these things:
- The name represententing a catalog.
- Total files and subfolders in the directory
- Total .java files in the folder
- Total java lines in the folder. (If I have a .java file with 200 lines, and another one with 23 lines, the output should be 223).
So I found total files and subfolders in the directory using this code, but it's kind of harder to find total .java files, and total lines.
My code for total .java files:
public void javaFiles(String file) {
String files;
File name = new File(file);
File[] list = name.listFiles();
for(int i = 0; i<list.length; i++) {
if(list[i].isFile()) {
files = list.getName();
if(files.endsWith(".java") || files.endsWith(".JAVA"))
output.append(files.length() + "\n");
}
}
}
This somehow doesn't work. Shouldn't I use files.length() when I want total sum of .java files?