Re: New File with a Directory



Mark Thornton wrote:
Alan wrote:
I was wondering why Java behaves this way. . . . Below are a few
lines of code with nearly duplicate methods called for a file and then
a directory. One method (methodWithoutNew) just assigns a File
variable to the input File object (no "new" operator). The other
method (methodWithNew) uses the "new" operator to create its file
object with the same name as the input File object.

{ System.out.println( file.getName() + " does not exist!!!" ); }

The reason would be more obvious if you replaced file.getName() with file in all of the print statements (in this context file is equivalent to file.toString()).

Alan: is just the name enough, without the whole path, enough to find the file to see if it exists?

--
Lew
.



Relevant Pages

  • Re: New File with a Directory
    ... Alan wrote: ... lines of code with nearly duplicate methods called for a file and then ... variable to the input File object. ... Mark Thornton ...
    (comp.lang.java.programmer)
  • Re: New File with a Directory
    ... Lew wrote: ... lines of code with nearly duplicate methods called for a file and then ... variable to the input File object. ... The reason would be more obvious if you replaced file.getNamewith file in all of the print statements ). ...
    (comp.lang.java.programmer)