Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > why construct file with "", the path of the file return "/"?

Reply
Thread Tools

why construct file with "", the path of the file return "/"?

 
 
junzhang1983@gmail.com
Guest
Posts: n/a
 
      02-29-2008
l am a little puzzled, why the file's behavior like this:

File fl = new File("","1.txt");
System.out.println(fl.getName());
System.out.println(fl.getParent());
System.out.println(fl.getPath());
System.out.println(fl.getAbsolutePath());
try {
System.out.println(fl.getCanonicalPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

the output is:
1.txt
\
\1.txt
D:\1.txt
D:\1.txt

why "" path, java process it as "/"?
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      02-29-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> l am a little puzzled, why the file's behavior like this:
>
> File fl = new File("","1.txt");
> System.out.println(fl.getName());
> System.out.println(fl.getParent());
> System.out.println(fl.getPath());
> System.out.println(fl.getAbsolutePath());
> try {
> System.out.println(fl.getCanonicalPath());
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> the output is:
> 1.txt
> \
> \1.txt
> D:\1.txt
> D:\1.txt
>
> why "" path, java process it as "/"?


From the docs

"If parent is the empty abstract pathname then the new File instance is
created by converting child into an abstract pathname and resolving the
result against a system-dependent default directory."

--

Knute Johnson
email s/nospam/knute/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Behavior of if construct in switch case defualt construct. Mukesh C Programming 4 03-26-2010 12:38 PM
Does the following construct qualify as overloading on return type ? Nikhil.S.Ketkar@gmail.com C++ 0 08-15-2008 08:35 AM
why construct file with "", the path of the file return "/"? junzhang1983@gmail.com Java 0 02-29-2008 03:47 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM



Advertisments