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]

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. =)
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.
> 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.