• Post Reply Bookmark Topic Watch Topic
  • New Topic

To get full path with JFileChooser

 
abhinav sinha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to get the full path (of a selected file) while opening a file through JFileChooser.Right now,when I am selecting a file,only the file name is displayed.But I want to display the full path.Here is part of my code -

-----------------------------------------------------------------------
<code>
public void mouseClicked(java.awt.event.MouseEvent e) {
if (jButton.isEnabled())
{
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.showOpenDialog(null);
File selectedPfile = chooser.getSelectedFile();
jTextField1.setText(selectedPfile.getName());
}
}

<\code>
-------------------------------------------------------------------------

Please let me know how to get display the full path in the jTextField1.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by abhinav sinha:
Hi,
I need to get the full path (of a selected file)
.......
Please let me know how to get display the full path in the jTextField1.


Try using the following methods from File class

getPath()
getAbsolutePath()


Try replacing your code


with



I think this will resolve your problem.
 
abhinav sinha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your suggestion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!