Re: creating/copying files..




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




.



Relevant Pages

  • Re: creating/copying files..
    ... 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. ... Creates a new File instance from a parent abstract pathname and a child pathname string. ...
    (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: creating/copying files..
    ... > Mark Thomas wrote: ... >> create, say a FileWriter passing this File object to the constructor, you ... > pass this File Obj to constructor when creating the file... ... Frances ...
    (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.programmer)