Results 1 to 5 of 5
Thread: How to save path of a file
- 11-22-2012, 02:54 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
How to save path of a file
Hello,
As i am very new to programing i wasn't sure where to post this question.
I have a program to open a file. Doesnt do anything at the moment, What i need to know is how to save the "PATH" of the file to a variable to use later. THis is what i have right now, not sure how to go about this.
Java Code:public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("dir")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.showOpenDialog(frame); }
- 11-22-2012, 03:03 AM #2
Re: How to save path of a file
If you have a File object you will always be able to access its Path.
- 11-22-2012, 03:17 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: How to save path of a file
I have figured it out somewhat. Still need help though. This is only returning the Current Directory. what i need is the full PATH. As in c:\folder\folder\file.txt
Java Code:public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("dir")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.showOpenDialog(frmndVirtualFighter); //File selFile = chooser.getSelectedFile(); File selFile = chooser.getCurrentDirectory(); String pathName; pathName = chooser.getName(selFile); JOptionPane.showMessageDialog(frame, pathName, "About", JOptionPane.PLAIN_MESSAGE);
-
Re: How to save path of a file
As Junky suggests, use the JFileChooser to select the File, but not to get the path String. Instead call one of the several available File methods on the chosen file, here selFile, to get the path String, methods such as getCanonicalPath() or one of the several others that you can find on the File API.
Last edited by Fubarable; 11-22-2012 at 03:23 AM.
- 11-22-2012, 03:33 AM #5
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
(in Java mysql to excel) where i have specify the path to save the file
By raj.mscking@gmail.com in forum New To JavaReplies: 3Last Post: 06-04-2012, 11:23 AM -
Java save to file / open from file - trouble
By joelBeaton in forum Advanced JavaReplies: 6Last Post: 03-23-2012, 01:47 PM -
How do you make a file save with a default file extension?
By Dark in forum New To JavaReplies: 3Last Post: 06-21-2011, 05:51 PM -
save file based on file extension
By masa in forum AWT / SwingReplies: 4Last Post: 05-11-2010, 12:17 PM -
How to show or open a file download or file save dialog box
By java_bond in forum New To JavaReplies: 0Last Post: 03-05-2010, 05:21 AM
Bookmarks