Re: creating/copying files..
- From: Frances <fdr58@xxxxxxxxx>
- Date: 29 Dec 2005 03:05:23 +0100
Mark Thomas wrote:
Frances
You need to realise that there is a difference between creating a File object, which is what the constructor does, and creating an actual File on your computer.
Very simply, if I write:
File myFile = new File("sample.txt");
I now have a file object in memory which will eventually 'represent' a file on the hard disc. This is the file "instance" you mention. I can now check to see if there already is a file of this name by using "if (myFile.exists())...". I can create an actual file on the hard disc by calling:
myFile.createNewFile();
Now the picture is complete. We have an instance of the File class in memory which is acting as a proxy for the real file on disc. If You now create, say a FileWriter passing this File object to the constructor, you can now start writing to the real file.
Hope that helps.
Mark
Mark, that helps A LOT, thank you.. this is precisely the kind of explanation I needed, it's very clear now.. create File Obj then pass this File Obj to constructor when creating the file...
:) thanks again.... Frances
.
- Follow-Ups:
- Re: creating/copying files..
- From: Rhino
- Re: creating/copying files..
- References:
- creating/copying files..
- From: Frances
- Re: creating/copying files..
- From: Mark Thomas
- creating/copying files..
- Prev by Date: Re: creating/copying files..
- Next by Date: Re: creating/copying files..
- Previous by thread: Re: creating/copying files..
- Next by thread: Re: creating/copying files..
- Index(es):
Relevant Pages
|