• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How different between File.exists() and File.canRead() ???

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my program must check that
if the path that user input is correctly or not
(path on the server-side)

i have to check that the path is correct or not
which method is for this case ? File.canRead() or File.exists() ??

thanks
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.io.File;
From the API:

"public boolean exists()Tests whether the file or directory denoted by this abstract pathname exists.

"public boolean canRead()Tests whether the application can read the file denoted by this abstract pathname.

One tests whether or not the file is there and the other tests whether or not it can be read (for instance that the file does not have a lock on it and can actually be read)...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can imagine many situations where File.exists() returns true, but File.canRead() will return false. Tom gives one example. Another example is if the file is on a Unix-like system with permissions set to 600 (i.e. only the owner can read and write to the file), then File.canRead() will return false if you are not the owner.

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic