Re: creating/copying files..
- From: Mark Thomas <anon>
- Date: Wed, 28 Dec 2005 23:24:26 +0000
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
Frances wrote:
Pls, what is best way to create or copy files?
in java.io.file I see under the constructors:
Creates a new File instance from a parent abstract pathname and a child pathname string.
what is a file "instance"?
I mean if I want to create an html file, then write into it, how would I do that?
(FileWriter is just for writing into files, not creating them.. is this right?) thanks..
Frances
.
- Follow-Ups:
- Re: creating/copying files..
- From: Frances
- Re: creating/copying files..
- References:
- creating/copying files..
- From: Frances
- creating/copying files..
- Prev by Date: Re: creating/copying files..
- Next by Date: Re: GUI program locking up...
- Previous by thread: Re: creating/copying files..
- Next by thread: Re: creating/copying files..
- Index(es):
Relevant Pages
|