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

Discussion in 'Java' started by junzhang1983@gmail.com, Feb 29, 2008.

  1. Guest

    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 "/"?
     
    , Feb 29, 2008
    #1
    1. Advertising

  2. 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
     
    Knute Johnson, Feb 29, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    902
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,963
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    0
    Views:
    288
  4. Replies:
    0
    Views:
    310
  5. Mukesh
    Replies:
    4
    Views:
    625
    Paul N
    Mar 26, 2010
Loading...

Share This Page