Here you can find the source of okToWriteFile(Frame parent, String fileName)
public static boolean okToWriteFile(Frame parent, String fileName)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.awt.*; import java.io.*; public class Main { public static boolean okToWriteFile(Frame parent, String fileName) { File f = new File(fileName); if (f.isDirectory()) { JOptionPane.showMessageDialog(parent, fileName + " is a directory.", "Error!", JOptionPane.ERROR_MESSAGE); return false; } else if (f.exists()) { int saveAnswer = JOptionPane.showConfirmDialog(parent, "File " + fileName/*from w w w .j a v a2s. c om*/ + " already exists.\nDo you want to overwrite?", "Question", JOptionPane.OK_CANCEL_OPTION); return (saveAnswer == JOptionPane.OK_OPTION); } return true; } }