The following code shows the problem I am experiencing:
// Assume working directory is empty.
File foo = new File("asdf");
foo.createNewFile(); // returns true, creates file "asdf" in working directory.
File bar = new File("asdf");
bar.mkdir(); // returns false
When I try to make a directory with the same name as a file that already exists, the "mkdir()" function returns false. A similar problem occurs when the operations are performed in the opposite order; when the directory is made first, the "createNewFile()" function returns false.
I understand that when the second "File" object is initialised it 'finds' the file created on the previous line therefore "bar.exists() && bar.isFile()" is true.
Please could someone detail how I can create a file with the same name as an existing folder and vice-versa.
Thanks, Harri
It's impossible, since your operating system (file system) does not permit it. Not a Java issue as such.