| Author |
Files in Java
|
Cecil Phillip
Ranch Hand
Joined: Nov 05, 2001
Posts: 40
|
|
What I noticed in Java is the if I declare a File oject and initialize it to a File, lets say File test = new File("C:\java","testfile.java"); When I used a BufferedReader to write to the File object, the actual file (testfile.java) will be created. However if I initialize it with a directory that doesn't exist an exception is thrown. What I want to know is why is that the file would be created if it doesn't exist, but the direcctory wouldn't? Also how could I create that directory?
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
The class File has a method called mkdir()...
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Adam Blinkinsop
Greenhorn
Joined: Mar 22, 2002
Posts: 7
|
|
Originally posted by Cecil Phillip: What I want to know is why is that the file would be created if it doesn't exist, but the direcctory wouldn't?
java.io.File objects aren't really files, but filenames. You can create any legal filename you want, it doesn't have to exist (see the 'exists()' method in the File class).
|
 |
 |
|
|
subject: Files in Java
|
|
|