• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Relative to what?
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably to System.getProperty("user.dir").
 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My fault, I was being vague.

I mean the path relative to the directory where the jar is located.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why wouldn't an absolute path work with new File(...)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic