aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IO question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IO question" Watch "IO question" New topic
Author

IO question

Wai Iu
Ranch Hand

Joined: Apr 04, 2000
Posts: 39
What will be the output? Consider a directory structure like
this (NT or 95) C:\JAVA\12345.msg --FILE
//CODE_A
import java.io.*;
public class IO {
public static void main(String args[])
{
File f1 = new File("\\12345.msg");
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());
}
}
The result will be
\12345.msg
\
true
12345.msg
false
false
If the line File f1 = new File("\\12345.msg")in the above code
is replaced with File f1 = new File("12345.msg"), the result
will be
12345.msg
null
false
12345.msg
true
true
Moreover, if the line File f1 = new File("\\12345.msg")in the
above code is replaced with File f1 = new File("..\\12345.msg"),
the result will be
..\123345.msg
..
false
12345.msg
false
false
What is the deifference between "..\\12345.msg", "12345.msg",
and "\\12345.msg"? which one stands for file? which one stands
for path? I am quite confusing about these concepts in File
class? Please help me.
Thanks!
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Let's pretend you are running your code from
C:\myStuff\myMessageHere
Then,
"12345.msg" looks for file C:\myStuff\myMessageHere\12345.msg
"\\12345.msg" looks for file C:\12345.msg
"..\\12345.msg" looks for file C:\myStuff\12345.msg
In other word,
1/ file 12345.msg in the current directory
2/ file \12345.msg at the root directory of your system
3/ file ..\12345.msg in the next parent directory
Hope it helps,
JRoch
Wai Iu
Ranch Hand

Joined: Apr 04, 2000
Posts: 39
Thanks, Jroch!
Your comments are really help me understand File class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IO question