using jfilechooser

i am using jfilechooser to export the grid datas to csv format, while saving it , it should look for whether the file already exists, if it exists it should a message, similary if the file exists and remains open, it show another message

can anybody guide me in this regard

regards

senthil

[314 byte] By [Senpolya] at [2007-11-27 10:21:07]
# 1

This has nothing to do with JFileChoose actually. You'll need to use the File class or more the specifically the File returned from the JFileChooser and use the exists() method to determine whether the File exists on the disk and do what you need to do accordingly. Below is an example of a saveFile method you can modify and use. It only provides the basic idea, not a complete running code.

public void saveFile() {

int val = chooser.showSaveDialog( parentComp );

if(val == JFileChooser.APPROVE_OPTION) {

File file = chooser.getSelectedFile();

if(file != null && file.exists()) {

val = JOptionPane.showConfirmDialog(parentComp, "Replace Existing File",

"Confirm Replace", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);

if(val == JOptionPane.YES_OPTION) {

// do file write code here

}

} else {

// you optionally restart the save method here

saveFile();

// or do something else if you do not want retry a save

}

}

}

ICE

icewalker2ga at 2007-7-28 17:08:06 > top of Java-index,Desktop,Core GUI APIs...