import java.io.*;
class Demo
{
public static void main(String args[])
{
File f=new File("1234.msg");
String arr[]=f.list();
System.out.println(arr.length);
}
}

Answers were Sorted based on User's Feedback



import java.io.*; class Demo { public static void main(String args[]) { File f=new File("1..

Answer / sri

this code gives Nullpointer exception

Is This Answer Correct ?    6 Yes 0 No

import java.io.*; class Demo { public static void main(String args[]) { File f=new File("1..

Answer / sarath

so what is your question..?
the code gives compilation error... because it should throw a IOException..

Is This Answer Correct ?    4 Yes 4 No

import java.io.*; class Demo { public static void main(String args[]) { File f=new File("1..

Answer / meziane

The list() of the class java.io.File "returns an array of Strings naming the files and directories in the directory denoted by this abstract pathname."

http://docs.oracle.com/javase/6/docs/api/java/io/File.html#list%28%29

The abstract pathname is the path specified in File f = new File(patAsString).
The method returns null, if the abstract pathname does not denote a directory (i.e an existing directory).
No compilation error.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is Collections API?

1 Answers  


How do you sort in java?

0 Answers  


Explain the protected field modifier?

0 Answers  


How do you insert a line break?

0 Answers  


What is the difference between preparedstatement and statement in java?

0 Answers  






Why is an interface be able to extend more than one interface but a class can’t extend more than one class?

0 Answers  


What do you mean by inner class in java?

0 Answers  


Which is better arraylist or vector?

0 Answers  


Which method must be implemented by all threads?

0 Answers  


Why hashmap is used in java?

0 Answers  


what is mean by String and StringBuffer? What is mean by Methooverriding and Overloading?

2 Answers   Satyam,


What is map in java?

0 Answers  


Categories