• Post Reply Bookmark Topic Watch Topic
  • New Topic

File object does not detect xml file in a folder  RSS feed

 
Giriraj Gupta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

File dir = new File(".");
String[] files = dir.list();
for( int i = 0; i < files.length; i++ ){
String filename = files[i];
File f = new File(filename);
if(f.exists())
{
System.out.println("File is Exists" );
}
if(f.isFile())
{
System.out.println("file=" + files[i]);
}
This code does not show xml file in a directory.
where is the problem in this code?

Help me.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Are you certain it is accessing the correct directory - is it showing other files in that directory? What directory "." is depends on various factors, e.g. in a web app it's rarely what you might think it is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!