File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How do I get the relative path if the user selects a file in a JFileChooser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I get the relative path if the user selects a file in a JFileChooser?" Watch "How do I get the relative path if the user selects a file in a JFileChooser?" New topic
Author

How do I get the relative path if the user selects a file in a JFileChooser?

Daniel Gallant
Greenhorn

Joined: Sep 09, 2009
Posts: 27
I have a new problem. I have a JDialog with a JFileChooser that the user uses to select a new image file. The problem I have is getting the relative path from the user input. I can get an absolute path, but that does not work with new File(path), where path is the absolute path, not a relative one.

Is there a simple method I'm missing to convert this?

Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Relative to what?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

Probably to System.getProperty("user.dir").


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Daniel Gallant
Greenhorn

Joined: Sep 09, 2009
Posts: 27
My fault, I was being vague.

I mean the path relative to the directory where the jar is located.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why wouldn't an absolute path work with new File(...)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I get the relative path if the user selects a file in a JFileChooser?