覆盖JFileChooser java

覆盖JFileChooser java,java,swing,user-interface,Java,Swing,User Interface,大家好,有人能告诉我正确的代码,以便在文件被覆盖时发出确认消息吗 { int index = cCont.getSelectedIndex(); log.info("index=" + index); if (m_att.getEntryCount() < index) return; String fileName = getFileName(index); String ext = fileName.substring (

大家好,有人能告诉我正确的代码,以便在文件被覆盖时发出确认消息吗

    {
    int index = cCont.getSelectedIndex();
    log.info("index=" + index);
    if (m_att.getEntryCount() < index)
        return;
    String fileName = getFileName(index);
    String ext = fileName.substring (fileName.lastIndexOf("."));
    log.config( "Ext=" + ext);

    JFileChooser chooser = new JFileChooser();
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "AttachmentSave"));
    File f = new File(fileName);
    chooser.setSelectedFile(f);
    //  Show dialog
    int returnVal = chooser.showSaveDialog(this);
    if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
    File saveFile = chooser.getSelectedFile();
    if (saveFile == null)
        return;
    log.config("Save to " + saveFile.getAbsolutePath());
    m_attachment.getEntryFile(index, saveFile);
}
{
int index=cCont.getSelectedIndex();
log.info(“index=“+index”);
if(m_att.getEntryCount()
JFileChooser所做的一切就是返回所选的
文件。因此,一旦获得所选文件,您需要检查它是否存在,然后提示用户确认

因此,基本准则是:

if (saveFile.exists())
{
     int response = JOptionPane.showConfirmDialog(...);
}
有关更多信息和工作示例,请查看上的Swing教程部分

if (saveFile.exists())
{
     int response = JOptionPane.showConfirmDialog(...);
}