|
|
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
SCJP 5.0 Mock Questions - Java File IO Package (15 Questions)
1) Imagine that you have directory called test1 in C drive containing some files, within which there is a directory called test2 (sub-directory of test1) containing some other set of files. Considering this, what statements are true about the following program?
package io;
import java.io.File;
import java.io.FileFilter;
public class DirLister {
public static void main(String[] args) {
String path = "C:\\test1";
list(path);
}
static void list(String path){
File fileObject = new File(path);
if (fileObject.exists()){
if (fileObject.isDirectory()){
System.out.println("Dir-->" + fileObject.getAbsolutePath());
File allFiles[] = fileObject.listFiles(new MyFileLister());
for (File aFile : allFiles){
list(aFile.getAbsolutePath());
}
}else{
System.out.println("File-->" + fileObject.getAbsolutePath());
}
}
}
}
class MyFileLister implements FileFilter{
@Override
public boolean accept(File pathname) {
return pathname.getAbsolutePath().endsWith(".bmp");
}
}
- The program will list down all the files within the directory test1 and test2
- The program will list down only the files in directory test1
- The program will list down only the files in directory test2
- The program will run infinitely.
Answer
1)1
The program recursively traverses over the directories and the files. Hence answer 1 holds good.
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
|