yesman
yesman

Reputation: 7838

Java file.exists() can't find an XML file

I'm simply trying to find whether an XML file exists or not. I have this code:

File f = new File("customers/jim.xml");
File g = new File("customers/jim.txt");

  if(f.exists())
      {
          System.out.println("File f exists!");
      }
      else
      {
          System.out.println("File f not found!");
      }

  if(g.exists())
      {
          System.out.println("File g exists!");
      }
      else
      {
          System.out.println("File g not found!");
      }

The output:

File f not found!
File g exists!

The text file is found, the xml one not. Both files are in the same folder, and the spelling is indeed correct. Anyone know what I'm doing wrong?

Upvotes: 0

Views: 2171

Answers (1)

RFon
RFon

Reputation: 118

Everything looks correct so a few things to check:

  • Capital letters in the extension.
  • Hidden extra extension (jim.xml.txt but .txt hidden)
  • Do you have several customers directories? If so, your application might be looking in another one than you are expecting.

Upvotes: 3

Related Questions