Results 1 to 6 of 6
- 07-15-2011, 10:01 PM #1
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
How to grab directory from a JFileChooser?
When I use a JFileChooser, I wish it would "remember" the last directory opened, but it always reverts back to \MyDocuments or something (where I NEVER place anything). I have to bubble up a gazillion levels and then back down again to locate the file I want.
Does the JFileChooser make this info available anywhere, so that I can store it for subsequent FileOpen (or Save) operations?
IOW, in addition to:
it would be nice if there was something like:Java Code:fileDisposition = fc.getSelectedFile();
(fc is a JFileChooser, and fileDisposition is a File)Java Code:fileDisposition = fc.getSelectedDirectory();
- 07-15-2011, 10:29 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
A directory is a File. So, you can just use getSelectedFile() method.
- 07-15-2011, 11:06 PM #3
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
What I got back from getSelectedFile() is the filename only, no path info. This code:
sets lblDispatchFileName's text from "Dispatch File = " to "Dispatch File = DispatchFileTest.txt" for example (not "Dispatch File = C:\SorterSim\Data\DispatchFileTest.txt"Java Code:fileDispatch = fc.getSelectedFile(); lblDispatchFileName.setText(String.format( "%s%s", lblDispatchFileName.getText(), fileDispatch.getName()));
- 07-15-2011, 11:12 PM #4
Read the API doc for the File class. It has lots of methods to get paths.
The name of a file does not include the path.
- 07-15-2011, 11:26 PM #5
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
- 07-16-2011, 07:03 AM #6
Similar Threads
-
how to grab info from array
By skuzzie in forum New To JavaReplies: 3Last Post: 12-09-2010, 01:26 PM -
JFileChooser start in .jar directory
By Sandia_man in forum AWT / SwingReplies: 2Last Post: 08-30-2010, 08:15 PM -
Trying to login to a website then grab another page
By DaveTheAve in forum New To JavaReplies: 6Last Post: 04-14-2010, 09:44 PM -
grab the textfile
By Sticks_ll in forum New To JavaReplies: 3Last Post: 03-31-2009, 01:23 PM -
JFileChooser example (selecting a directory)
By Java Tip in forum Java TipReplies: 1Last Post: 02-03-2009, 01:25 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks