Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

FileChoosers - currentDirectory

  Asked By: Clifton    Date: Sep 11    Category: Java    Views: 617
  

I'm having a bit of trouble figuring a simple problem.
I'm using the latest swing version and JDK. I want to, from a file selected
by the user in th fileSelector dilaog provided as standard create a
fileReader. I have been able to create one with just the name of file. but
that isn't much use unless working with just files in the directory that the
class file is located in.
How would I go about using the whole path & name to create the FileReader?
I've tried variuos things and searched the net for a bit but can't really
find a very useful answer, although I expect I have looked over something.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Alfonsine Miller     Answered On: Sep 11

JFileChooser chooser = new JFileChooser();
if(chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION){
File file  = chooser.getSelectedFile();
FileReader reader = new FileReader(file);
}


This is just a minimal bit  of code, but it should do the job. There are
lot of other features that you can use as well, such as file filters,
but I will leave that up to you. You can also take a look at the Java
API documentation for the JFileChooser and see the example they provide.

 
Didn't find what you were looking for? Find more on FileChoosers - currentDirectory Or get search suggestion and latest updates.

Related Topics:




 
 
 
 

Related Post