Re: java getPath getAbsolutePath getCanonicalPath and JFileChooserreuse

Discussion in 'Java' started by Jon A. Cruz, Jul 9, 2003.

  1. Jon A. Cruz

    Jon A. Cruz Guest

    Krick wrote:
    > Can someone explain why I should use of the following java File
    > methods over any of the others...
    >
    > getPath()
    > getAbsolutePath()
    > getCanonicalPath()
    >
    > They seem to always return the same thing in my testing.



    Then you need to test some different cases.

    :)

    For one, try paths with ".." in them. That is, the common "back up one
    directory" expression.


    For another, try paths using hard and soft symlinks. (Hmmm... might need
    Unix or Linux for that one). Or aliases. Etc.

    Try some paths that start at the root of your filesystem.

    Try some paths that start with ".."


    But most importantly...

    *****
    Try reading the API docs on them. They actually cover a lot of that.
    *****
    http://java.sun.com/j2se/1.4.1/docs/api/java/io/File.html


    > Ultimately, what I am trying to do is give the user a JFileChooser to
    > open a file. After they've selected a file and hit ok, I want to
    > cache the path to the directory that the chosen file was in so I can
    > use it as a starting directory for subsequent creations of
    > JFileChooser.


    Ahhh....


    Read the API docs and it will be quite clear to you.
    Or... look up "canonical" in the dictionary for a clue. They named it
    that for a reason. :)


    > Hmm... I just had a thought... Can I create and re-use a single
    > instance of JFileChooser? If so, does it retain the path where it
    > was when it was last closed?


    Instead, how about just asking the JFileChooser?

    http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/JFileChooser.html#getCurrentDirectory()


    // Once a selection is made (and not canceled)
    mlastDir = myChooser.getCurrentDirectory().getCanonicalFile();


    ....
     
    Jon A. Cruz, Jul 9, 2003
    #1
    1. Advertising

  2. Jon A. Cruz

    Roedy Green Guest

    Re: java getPath getAbsolutePath getCanonicalPath and JFileChooser reuse

    On Wed, 09 Jul 2003 08:51:27 -0700, "Jon A. Cruz" <>
    wrote or quoted :

    >Then you need to test some different cases.


    I think Star Trek scared people off experimenting. If anyone made an
    error, the computer invariably exploded. In real life, you can learn
    a lot from just trying out methods with a variety of data and see what
    happens. Gradually the light dawns and the documentation begins to
    make sense. Looking at Sun's source code in src.zip also helps too.

    With Slickedit, I just right click on any method, variable or class
    and I can see the corresponding source code in scr.zip along with
    Javadoc.

    Sun does not like to use examples. I do. Quite often you will find
    examples of what the various methods do in the Java glossary,
    including the various file naming methods.

    see http://mindprod.com/jgloss/file.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jul 9, 2003
    #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. Roedy Green
    Replies:
    0
    Views:
    743
    Roedy Green
    Jul 9, 2003
  2. RonRan

    Doubt in getCanonicalPath

    RonRan, Nov 21, 2005, in forum: Java
    Replies:
    2
    Views:
    546
    RonRan
    Nov 24, 2005
  3. Chris Uppal
    Replies:
    0
    Views:
    496
    Chris Uppal
    Jun 27, 2006
  4. Sathyaish
    Replies:
    4
    Views:
    823
  5. Connolly

    GetPath to variable

    Connolly, Dec 11, 2007, in forum: Python
    Replies:
    3
    Views:
    1,003
Loading...

Share This Page