Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

CreateNewFile() not working, canRead() & canWrite() both true

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I've been having this issue for a week and no amount of Google searches has helped me figure it out. My interface is written in Swing, but I use the AWT FileDialog to have the user choose a file to save their data to. (I chose this method because it uses the native file chooser since the JFileChooser is absolutely horrid and completely unusable on Mac) Once the user chooses the file, I get the File from the FileDialog object and then check if it exists. If it does not, I use the File class's createNewFile() method. However, the method returns false and does not create a new file. canRead() and canWrite() both return true. I have tried choosing several different locations to save to, (even the root directory) but I get exactly the same result no matter where I choose. Is there something I am missing?
Here is my code:



The System.out.println() displays this result:

file created: false Read/Write Permissions: true/true

and, of course, no file is actually created.
Just in case it makes a difference, here is my development environment info:

Intel based MacBook Pro, OS X 10.9.2
Eclipse, Version: Indigo Service Release 2, Build id: 20120216-1857
Java, Version 7, Build 51 (build 1.7.0_51-b13)

Can anyone please help me figure out why it's not creating a file?

Let me know if you need any other information. Thank you in advance, you guys here are all freaking awesome!
 
Marshal
Posts: 25670
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... if "database.exists()" returns true, you would see the output you are seeing.
 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an exclamation point in front of database.exists(), thus if it returns false, the code following the if statement would be executed.
 
Paul Clapham
Marshal
Posts: 25670
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, let me put that more clearly. If "database.exists()" returned true then the code controlled by the if-statement would not be executed, and then the output you observe would be the output of that code. So my hypothesis is that "database.exists()" returns true. That's a testable hypothesis.
 
    Bookmark Topic Watch Topic
  • New Topic