Results 1 to 3 of 3
  1. #1
    DarkGhetto22 is offline Member
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Default to overwrite with showSavedDialog!!!

    Well my problem is i cant get to overwrite a file using a showSavedDialog, i got the next code, i hope to get any answer and thanks you very much for the atencion:

    PHP Code:
    else if(e.getSource() == guardar){
    
                JFileChooser chooser = new JFileChooser();
                int returnVal = chooser.showSaveDialog(null);
    
                if(returnVal == chooser.APPROVE_OPTION){
                    File f = chooser.getSelectedFile();
                    String fileName = f.getPath();
    
                    if(f.exists()){
                        int resultado = JOptionPane.showConfirmDialog(null,
                                "This file already exist!! " +"¿Would you like to overwrite on it?",
                                "this file already exist",
                                JOptionPane.YES_NO_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                                switch(resultado){
                                    case JOptionPane.YES_OPTION:
                                        //here is my trouble, if any one has a idea, ill really thanks very much
                                        
                                    break;
    
                                    case JOptionPane.NO_OPTION:
                                        JOptionPane.showMessageDialog(null, "So sad to say good bye!!! :("
                                                                             + "\nI hope to see you soon again :P");
                                        System.exit(0);
                                        break;
    
                                    case JOptionPane.CANCEL_OPTION:
                                        return;
                                }
                          }
    
                    try{
                        FileWriter fw = new FileWriter(fileName);
                        BufferedWriter bw = new BufferedWriter(fw);
                        PrintWriter salida = new PrintWriter(bw);
                        salida.print(texto.getText());
                        salida.close();
    
                    }catch(IOException ie){
                        JOptionPane.showMessageDialog(null, "Error al crear archivo" + ie);
                    }
                  }
               }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    //here is my trouble,
    What trouble would that be?

    Are you getting errors? Then copy and paste the exact and full error messages.
    Do you not know how to write to the file? Then gooogle for a IO tutorial.

    When you have a more specific question comeback and ask it.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agree that so far there really isn't an answerable question in the original post, but rather a "code dump". Please check out the link in my signature on how to ask smart questions for tips on what to include in your questions here so that they are answerable.

    Best of luck and welcome to the java-forums.

Similar Threads

  1. pdfbox to overwrite image on a pdf
    By vammpiro in forum Advanced Java
    Replies: 1
    Last Post: 03-09-2012, 03:54 PM
  2. Replies: 3
    Last Post: 02-16-2009, 09:20 PM
  3. file overwrite method
    By nanaji in forum Advanced Java
    Replies: 5
    Last Post: 11-14-2008, 09:19 AM
  4. Create and overwrite files
    By wmrwl in forum New To Java
    Replies: 7
    Last Post: 10-01-2008, 04:16 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •