This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19649
    
  18

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?
 
Similar Threads
In JFileDialog how to use the save window
Link from jsp to html
Calling class in jsp
NX: DB File Location in suncertify.properties
Read Text File Using Relative Path.