https://www.dropbox.com/s/twtl38huxeeetsx/ProgettoApachePoi.rar

in this link there is my project, i create a java text editor for open docx documents. the text editor should do the basics functions of a text editor, as copy, paste , select all, delete, exit, new, open , save and save as. i tested the code and i have a problem only with the function "save", because the program don't do anything, but " save as" it run correctly. could someone help me to solve the problem. the part of the code that is about "save" is this:

  private void SaveActionPerformed(java.awt.event.ActionEvent evt) {                                     

        if("".equals(CurrentFileDirectory)){


        JFileChooser sdChooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Text file", "txt");
        sdChooser.setFileFilter(filter);
        int returnval = sdChooser.showOpenDialog(null);

        try{
            if(returnval == JFileChooser.APPROVE_OPTION){
            File directory = sdChooser.getCurrentDirectory();
               String path = directory.getAbsolutePath();
               String fileName = sdChooser.getSelectedFile().getName();
               if(fileName.contains(".docx")){

               }else{
                   fileName = fileName + ".docx";    
               }
               jTextArea.exportDocument(new FileOutputStream(new File(fileName)));
               //BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path + "\\" + fileName)));
               //bw.write(jTextArea.getText());
               //bw.close();}
            }
        }catch(IOException e){      
    JOptionPane.showMessageDialog(null, "ERROR!");
        }
    }
    }  

You've defined the "Save" function to work only if it's the first time that the user's trying to save the doc and CurrentFileDirectory is not blank. I wager you forgot to add an else condition to that: what if the file HAS been saved and CurrentFileDirectory is not blank?

Basically, there is no else to the if at line 3.

i try to remove the function "save" for have only "save as.." but now i have an output error with " save as -_-'

There was no need of doing that, I guess. Send the cde for "save as", and let me check that! BTW you understood why save wasn't working, right?

This article has been dead for over six months. Start a new discussion instead.