• 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

File question from JQPlus

 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question ID :1002740579101
What will the following are correct statments regarding this program, if it is run from directory: c:\work ?
Assume that file Abc.txt does not exist.

Options - (Choose two)
a) f.getPath will return c:\work\Abc.txt
b) f.getCanonicalPath will return c:\work\Abc.txt
c) f.getPath will return ..\work\Abc.txt
d) f.getAbsolutePath will return c:\work\Abc.txt
e) f.getAbsolutePath will return c:\work\..\work\Abc.txt
Answer and Explanation -
(b) and (e)
Creating a File object does not reqire the file to be present. It also does not create any file.
getPath : returns whatever was passed to the constructor of File class while creating a file object. So: Abc.txt
getAbsolutePath : returns the root path + whatever was passed to the constructor. So: c:\work\Abc.txt
getCanonicalPath : returns the root path + whatever was passed to the constructor - Any redundent path. For eg. for new File("../work/Abc.txt"), AbsolutePath is: c:\work\..\work\Abc.txt but CanonicalPath is c:\work\Abc.txt . Note that, it resolved the work/../work to simply work.
My Doubts -
1) Option c is is also right, I tested this and found true. (Try outputting these values from dir c:\work)
2) Explanation is incorrect because what is passed to the constuctor is - "../work/Abc.txt", also if (e) is right (c) has to be right, because (e) implies (c) as per the API.
Try running this code from c:\work directory -

Any comments?
TIA,
- Manish
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think your guesses are correct. If you can back up your statements with the code executions, then you are definitely right
I've notified the JQ+ team.
[ March 20, 2002: Message edited by: Valentin Crettaz ]
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct, but this question was fixed long back.
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Anil:
You are correct, but this question was fixed long back.


Really? Great!!!
How can I get the upgrade?
Thanks,
- Manish
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic