2

Possible Duplicate:
Java : File.exists() inconsistencies when setting “user.dir”

Why does this:

void test(){
  print(new File("downloads/"));
  print(new File("downloads/").getAbsoluteFile());
  print(new File("C:\\someDir\\downloads\\"));
}

void print(File dir){
  log.info(dir.getAbsolutePath() + " exists " + dir.exists() + " contains: " + (dir.list() != null ? dir.list().length : "") + " files");
}

prints this:

C:\someDir\downloads exists true contains: 0 files
C:\someDir\downloads exists true contains: 1 files 
C:\someDir\downloads exists true contains: 1 files

when executed via JUnit in Maven in Jenkins as a WebStart slave?

Community
  • 1
  • 1
Tim Büthe
  • 62,884
  • 17
  • 92
  • 129
  • Is it possible that you modified `user.dir` via `System.setProperty()`? If so, then that's your problem, because that's not supported! – Joachim Sauer Jul 09 '12 at 10:19
  • 1
    See this question: http://stackoverflow.com/questions/2275362/java-file-exists-inconsistencies-when-setting-user-dir – Joachim Sauer Jul 09 '12 at 10:19
  • @JoachimSauer: you are right, thanks! I gonna vote for close as duplicate. – Tim Büthe Jul 09 '12 at 12:00
  • Glad to have helped, I wouldn't have voted to close as duplicate without feedback (since it *could* have been a different problem), but if you can confirm that this is the same problem, then I'll vote to close as well. – Joachim Sauer Jul 09 '12 at 12:04

0 Answers0