Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java thinks new files are folders

Tags:

java

file

My java program keeps thinking that every new file is not a file but a folder.

I have been bug hunting and now it will not let me save a file using FileWriter. If I create a new File, and then check if it is a file or a directory, it says it is a directory.

I originally had a long path that was created, so I got rid of that. I also used to have the writing done in a separate thread, and got rid of that as well, but still the problem persists.

If I create a new class, with just a simple

java.io.File file = new java.io.File("test.csv");
output.print(file.isDirectory());

This comes out as true.

I can however still save graphics using javax.imageio.*

Can anyone help?

Edit: I am using eclispe 3.7.2 with java 1.7.0... File.isFile() is false, File.createNewFile() fails (java.io.FileNotFoundException (Access is Denied)). When looking in the directory I specify, there is a new folder there called test.csv. So it is creating a new folder, and is treating it as a folder, despite the fact that I am specifying it is a csv file. I have tried other file types, even no file type. But the same problem. It thinks it is a folder and not a file. This is just baffling me.

like image 374
Darkraiyy Avatar asked Dec 26 '22 17:12

Darkraiyy


1 Answers

Java's new File() does NOT create files or directories by itself. So you should show your code that does. I suspect that you have something like file.mkdirs(); somewhere - if your file is referring to "test.csv" at this point it will create a directory called "test.csv"

like image 181
Germann Arlington Avatar answered Dec 29 '22 10:12

Germann Arlington