Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse a File to String ??

Status
Not open for further replies.

paulbradley

Programmer
Oct 9, 2002
158
GB
I have the following code to get a file using a file chooser:
//**********
String filename = File.separator+"tmp";
JFileChooser fc = new JFileChooser(new File(filename));

fc.showOpenDialog(null);
File selectedFile = fc.getSelectedFile();

System.out.println(selectedFile);
Library lib = Library.load(selectedFile);
//****************
However, the last line won't compile as the filename passed to the load method in Library must be a String, can you parse the file name or is there another solution? Thanks.
 
What is the "Library" class ? Never heard of it ... you load a file very differently - using the FileInputStream class.

However, if it is just some custome class that actually does that, you can call :


Library lib;
if (selectedFile.exists()) {
lib = Library.load(selectedFile.toString());
} else {
// handle file not exist error
{


--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top