• 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

getPath()

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Consider the following piece of code and its output:
File is c:\java\12345.msg and the current directory is c:\java
import java.io.*;
public class IO {
public static void main(String args[]) {
File f1 = new File("\\12345.msg"); //1
System.out.println(f1.getPath());
System.out.println(f1.getParent());
System.out.println(f1.isAbsolute());
System.out.println(f1.getName());
System.out.println(f1.exists());
System.out.println(f1.isFile());
}
}
Output:
\12345.msg
\
true
12345.msg
false
false
Also if the line //1 is changed to
File f1=new File(12345.msg);
the output changes to
12345.msg
null
false
12345.msg
true
true

I don't understand why that happens. I think i don't get the \\12345.msg. Does it mean that the path is the current directory?
Let me list out what i understand. Can anyone tell me if anything is wrong?
1. If i just give just the file name as in 12345.msg, it means i have not given the complete path. That is why isAbsolutePath returns false in the second case.
2. getName() will always return only the file name, so there is no confusion there.
3. the results of exists() and isFile() are obvious.
4. Considering the second case, does getPath() and getParent() return information only relative to the current directory?
5. This is the most problematic part for me -- i think if i am clarified in this, everything will be clear -- What does \\12345.msg mean?

------------------
Regards,
Shree
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic