aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes File name in JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "File name in JDialog" Watch "File name in JDialog" New topic
Author

File name in JDialog

Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear all,

I have a problem with JDialog. I have a File->Open functionality in the Swing utility i'm developing. Whenever i open a JDialog box appears to the user to select the file and after he selects the file from the particular folder, the file name appears in the File Name textbox.

Suppose if the user tampers the file name before he clicks Open button in the JDialog box, how can i capture it and display a message to the user that the requested file is invalid.

Now, the utility is opening the file and also creates an extra new file in the folder with the tampered file name

Kindly provide your help.

Thanks & Regards,
Vijay
Tapan Maru
Ranch Hand

Joined: May 08, 2006
Posts: 65
//You will get a selected file name from the following method
File selectedFile = fileChooser.getSelectedFile();
//You will get a directory name from the following method
File currentDirectory = fileChooser.getCurrentDirectory();

// now check for the file in that directory

if (!new File(currentDirectory.getName()+selectedFile.getName())).exists()) {
JOptionPane.showMessageDialog(this, "File Not Found", "Error", JOptionPane.ERROR_MESSAGE);
}



//PLEASE CORRECT COMPILATION ERROR AND TYPO CORRECTIONS SPECIALLY IN BRACKETS IN IF CONDITION ABOVE


Tapan Maru
tapanmaru@gmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File name in JDialog