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 application system?

0 Answers  


Name component subclasses that support painting in java programming?

0 Answers  


How do you start a thread?

0 Answers  


What are the advantages of arraylist over arrays?

0 Answers  


I have one Shopping cart application, i that i have selected some items, while clicking submit button by mistake i have clicked twice or trice, that time items are selected twice or trice. Actually i want only one copy of items but its selected twice or trice. So how can we avoid this problem?

2 Answers   Honeywell,


Explain java coding standards for methods?

0 Answers  


What are generic methods?

0 Answers  


Where is const variable stored?

0 Answers  


Can we use string in the switch case?

0 Answers  


How many digits is int32?

0 Answers  


Which collection does not allow duplicates in java?

0 Answers  


Explain a few methods of overloading best practices in java?

0 Answers  


Categories