Could anybody pls tell me how I can set a default file name when JFile chooser Save dialog box appears so that the user doesn't need to name the file to be saved. And I also want to get the name of a file from current selected directory so that I can warn user for the replacement, The code I tried with is as follows
public void SaveAs()
{
String FileName="";
JFileChooser jfc = new JFileChooser();
int r = jfc.showSaveDialog(this);
if (r== JFileChooser.APPROVE_OPTION)
{
FileName = jfc.getSelectedFile().getPath();
FileName=FileName+".java";
writeFile(FileName);
}
}//End of SaveAs() Method
public void writeFile(String fn)
{
String contetnt="THIS IS A FILE";
try{
FileWriter fw = new FileWriter(fn);
fw.write(contetnt);
fw.close();
}catch(FileNotFoundException fnfe){}
catch(IOException ioe){}
}//End of writeFile(String fn) Method