Skip to main content

Saving a file with Illegal characters. Help

No replies
javaswingus
Offline
Joined: 2006-02-17
Points: 0

Hi,
Please see the code below. I try to save a file with illegal characters and I need to display an error message and then show the JFiechooser back. I am having problems here.

int tt = m_chooser.showSaveDialog(null);
if(tt == JFileChooser.CANCEL_OPTION)
{
....
}
else if (tt == JFileChooser.APPROVE_OPTION)
{
File file = m_chooser.getSelectedFile();
System.out.println("file name given :"+m_chooser.getSelectedFile().getName());

int specialChar = xmlFile.toString().indexOf('/');
System.out.println("specialChar :"+specialChar);
if(specialChar == -1)
{
JOptionPane.showMessageDialog(null,"Please remove any special characters used");
m_chooser.showSaveDialog(null);
return;
}
...
... // method to save
}

file name given is not printing all the file name specified. When I speicify "test/test.xml",
I only get "test.xml"

Can someone tell me how to handle illegal characters in JFileChooser? I am using J2SE version 1.4.1_01

Thanks