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

how can you catch multiple exceptions in java?

0 Answers   Cyient,


What is the difference between @before and @beforeclass annotation?

0 Answers  


Why we use static and synchronized in method for single thread model example: public static synchronized add(){}

2 Answers  


Can extern variables be initialized?

0 Answers  


What is string :: npos?

0 Answers  






What is a java applet? What is an interface?

0 Answers  


How will you print number in reverse (descending) order in BST.

0 Answers   GrapeCity,


What is the GregorianCalendar class?

2 Answers   HCL,


After compilation of java program we'll get .class code. If it's generated in OS Windows XP will it work on OS Linux? If yes why? If no why?

5 Answers   Aricent,


Explain importance of inheritance in java?

0 Answers  


What is the point of polymorphism java?

0 Answers  


Can you create an object of an abstract class?

0 Answers  


Categories