creating file problem

I'm new to Java so don't mind the simple question. All I'm trying to do is create a file but when i run

File file = new File("C:\\test.txt");

the file isn't being created. What could be the cause, i'm trying it on a windows system. The rest of the code is irrelevant because i'm just messing around with some of the File methods. Thanks!!

[365 byte] By [lokitsta] at [2007-11-26 16:09:54]
# 1
http://www.exampledepot.com/egs/java.io/CreateFile.html?l=rel
CaptainMorgan08a at 2007-7-8 22:32:15 > top of Java-index,Java Essentials,New To Java...
# 2
Try instead of using C:\, use a foreward slash instead (/). If it works, then the file created would be in the same location as your .java file. However, I'm still learning myself, so I don't know too much. =)
angryfirelorda at 2007-7-8 22:32:15 > top of Java-index,Java Essentials,New To Java...
# 3

That creates a File object. That's not the same as creating a file on the filesystem.

A File represents the idea of a file. The file itself may or may not exist (that's why there is an exists() method on File). A File object lets you see if a file exists, what permissions it has, and if it's a directory, it lets you lists the files in that directory.

If you want to actually create the file, then you can use a java.io.FileWriter or java.io.FileOutputStream.

paulcwa at 2007-7-8 22:32:15 > top of Java-index,Java Essentials,New To Java...
# 4
> Try instead of using C:\, use a foreward slash> instead (/). Backslashes are fine.> If it works, then the file created would> be in the same location as your .java file. ...No, it will be in the location he gave in the constructor.
CaptainMorgan08a at 2007-7-8 22:32:15 > top of Java-index,Java Essentials,New To Java...
# 5
oops. Thanks mate!
lokitsta at 2007-7-8 22:32:15 > top of Java-index,Java Essentials,New To Java...
# 6
>...No, it will be in the location he gave in the constructor.oops, thanks for pointing that out!
angryfirelorda at 2007-7-8 22:32:15 > top of Java-index,Java Essentials,New To Java...