Inside a for loop:
Why do I have to add a forward slash after the directory name? For example:
for(int i = 0; i<s.length; i++){
File f = new File(dirname + "/" + s[i] );
// Why to add "/" after dirname(i.e directory name)
if(f.isDirectory()){
System.out.println(s[i] + " is Directory" );
}else{
System.out.println(s[i] + " is File");
}
}
If I remove backslash "/" after dirname:
File f = new File(dirname + "/" + s[i] );
When I remove "/":
File f = new File(dirname + s[i] );
It won't differentiate between directory and file. All the files inside will be considered to be the file. After I add a backslash, it will be okay. And it will differentiate between directory and file. Why is that? Why do I have to add "/". The program is meant to look inside the file without adding "/".