Re: creating/copying files..



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
.



Relevant Pages

  • Re: creating/copying files..
    ... Mark Thomas wrote: ... 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. ... I now have a file object in memory which will eventually 'represent' a file on the hard disc. ...
    (comp.lang.java.help)
  • Re: quick ZipFile question
    ... > ZipFile takes a filename or a File object in the constructor. ... A common misunderstanding. ... IBM Australia - Tivoli Security Software ...
    (comp.lang.java.help)
  • Re: Segmentation Fault in fclose()...why?
    ... Bot one thing does stand out: ... > File object then you will call fclose with an uninitialized ... > pointer. ... managed by the constructor and destructor, ...
    (comp.lang.cpp)
  • Re: quick ZipFile question
    ... > ZipFile takes a filename or a File object in the constructor. ... A common misunderstanding. ... IBM Australia - Tivoli Security Software ...
    (comp.lang.java.programmer)