Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

File.mkdir() broken ?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a directory using File.mkdir() (and File.mkdirs()) but neither works! I don't get an exception, and mkdir returns true but when I check the file system no directory has been created and this is driving me up the wall!

I'm using the latest 1.4 JDK on OSX.

HELP!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Often files may not be located where you think they are - especially if the path is relative. Do you know for sure what the current working directory is when the code is executing? That's what your Java uses as the base, when evaluating relative paths. I suggest

to make sure you know what path the File is referring to. I suspect you'll find that the directory is getting created, but not where you expect.
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
Often files may not be located where you think they are - especially if the path is relative.



Hi, yes good idea but I'd already thought of that one: firstly I use absolute paths to create and also log the paths being used to create the dirs and to make extra sure I simplified the path to /trash (so it should have created /trash/backup) but still no joy.
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if this is a Mac-specific issue. Would you like me to move this thread to our Java-on-Mac forum?
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
I wonder if this is a Mac-specific issue. Would you like me to move this thread to our Java-on-Mac forum?



I was wondering the same thing and then I thought "hmm I've wrapped my mkdirs in asserts()" and yes lo and behold the reason why the dirs weren't being called is because mkdir was never called.
[ October 02, 2004: Message edited by: Edward Kenworthy ]
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! Well, glad you solved it.
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!