Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: how to get full path name from realtive path

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to get full path name from realtive path

    hi....
    i have made a java program, which is called inside a shell script.
    Now the filename is to be supppiled as a command line argument to shell like

    ./nsdnet.sh ./nsdnet_file.csv

    what i want is , this command line name should be interpreted as full path by the java code
    like /dialp/Release/bin

    and if we write
    as


    ./nsdnet.sh ../nsdnet_file.csv

    , then the filename should get expand to /dialp/Release/nsdnet_file.csv
    is this possible?

    plz help


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: how to get full path name from realtive path

    Write the Java code to browse everyfile on your pc until it finds it then you know the full path or you maybe able to make use of some of linux's search capabilities.

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: how to get full path name from realtive path

    You can use the getAbsolutePath() method in File.

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: how to get full path name from realtive path

    Doesn't that require you to gave the file object, not the file name...

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: how to get full path name from realtive path

    Create one then
    File myFile = new File("file.txt");
    myFile.getAbsolutePath();

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: how to get full path name from realtive path

    that would create it in the current directory, not what he is after
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  7. #7
    Junior Member
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to get full path name from realtive path

    test dghgfh dfgdfghdh

  8. #8
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: how to get full path name from realtive path

    isn't that the point of relative paths? so you don't have to type out the whole current directory?

    If you need a different directory (without knowing the complete address before-hand), this link is quite useful.
    Last edited by helloworld922; August 8th, 2009 at 12:40 PM.

  9. #9
    Junior Member
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to get full path name from realtive path

    thanx to all

    but i have found the way in unix...

Similar Threads

  1. Program to print current directory path to the console
    By JavaPF in forum Java Programming Tutorials
    Replies: 1
    Last Post: October 9th, 2009, 01:59 PM
  2. Probelm in Path and Paths Classes
    By neo_2010 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: July 14th, 2009, 11:39 AM
  3. [SOLVED] How to a set java class path?
    By captjade in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2009, 07:40 AM