Re: Is it correct about File.createNewFile()?



Red Orchid <windfollowcloud@xxxxxxxxx> wrote:
> File f = new File("re:test.txt"); // #1
>
> try {
> boolean b = f.createNewFile();
> System.out.println(b);
> }

> The "re:test.txt" in #1 is wrong pathname.
> The 'f' will not be created.
>
> But, the code above outputs "true".
>
> Is it correct?

It appears that a file is created by the name "re", and created. The
interpretation of the filename parameter to the File constructor is left
unspecificed, so you can't call the behavior wrong. So long as re-using
that File instance to recreate the same file again fails (which it does)
and opening a stream of that file reads back no data (which it does),
the spec is being fulfilled.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.



Relevant Pages

  • Re: is file exist
    ... write my code that consists of opening it and if opening fails, ... checking success is what you are supposed to do. ... so open it for reading and read (if it opens). ... The problem with this function is that if it fails it ...
    (microsoft.public.vc.language)
  • Re: documents with tables wont open
    ... If you saved the files directly from Word to your CD, chances are you ... corrupted them -- saving files directly to removable medium often does that. ... property, then try opening them. ... If it still fails, try Word's Recover Text ...
    (microsoft.public.word.docmanagement)
  • Re: Determining size of file
    ... This is opening the file in text mode. ... For a text stream, its file position indicator contains unspecified ... CLC FAQ ...
    (comp.lang.c)
  • Re: stripping newline from input
    ... They may be opening it as binary, ... certain MSDOS implementations allowed the user to decide ... whether a plain "r" or "w" means text stream or binary stream. ... Dan Pop ...
    (comp.lang.c)
  • Re: Upload script failing
    ... hosting it fails. ... stream: Permission denied in ...
    (comp.lang.php)