This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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:
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.
subject: CreateNewFile() not working, canRead() & canWrite() both true