Writing to file not working, might be 1.4 problem

Hi:
I am trying to writing the content of a JTextArea onto a file. The content is pretty big, has newlines. I have been struggling with this in 1.4 and it just doesn't write to the file I specified. In 1.3, it works great. Here is the rough code:
public void loadDisplayFrame()
     JMenuItem save = new JMenuItem("Save");
     //Save Action Listener
     save.addActionListener(new ActionListener()
        public void actionPerformed(ActionEvent ae)
           String filePath;
           //Save the  gsgl sample file
           if(filePath!=null && filePath.length()>0)
              try
              int state = saveChooser.showSaveDialog(null);
              File f;
              f = saveChooser.getSelectedFile();
              if(f!=null && state==JFileChooser.APPROVE_OPTION)
                    savedName = f.getPath();
                    if(!savedName.endsWith(".gsgl"))
                       JOptionPane.showMessageDialog(null, "Invalid file name", "error", JOptionPane.ERROR_MESSAGE);
                    }else
                       processSaving();
                    }catch(Exception e)
                        e.printStackTrace();
                }else
                    JOptionPane.showMessageDialog(null, "Please load a file first", "error",
                        JOptionPane.ERROR_MESSAGE);
          myMenu.add(save);
          JMenuBar displayMenu = new JMenuBar();
          displayMenu.add(myMenu);
  public void processSaving()
         try
             System.out.println("Saved Name is " + savedName);
           PrintWriter out
           = new PrintWriter(new BufferedWriter(new FileWriter(savedName)));
           //name of TextArea is <display>
           String saveCode = display.getText();
          System.out.println(saveCode);                 
             out.print(saveCode);
          out.close();
        }catch(Exception e)
          System.out.println("Exception in writing" + e.toString());
     Anyone knows what is going on? I am hoping to use 1.4 for my project. But this thing is not working. Any way around it? Thanx

Try putting in this line before your close:
out.flush();
PrintWriter buffers the data and won't send it until you exit or enough data gets into the buffer to cause a flush. I assume that you are getting a zero byte file. You can also construct a PrintWriter with a boolean to indicate if it should auto flush the buffer.
Hope that it helps.
Paul

Similar Messages

Maybe you are looking for

  • Installation problem with already installed apache, help!

    Alright, I have oracle 9i client installed on a windows 2000 machine. I'm admin (it is a laptop that dual boots Solaris and Windows 2000). I also had apache 2 and tomcat with jk2 connector. Normally I run a web app off of this laptop, connecting to a

  • Getting to data stored in time machine hard drive

    I was running time machine on my macbook pro, and tonight the logic board of the MBP died on me. There are several files I need ASAP on the (external usb) time machine drive. If I plug the drive to another mac (mac pro I have at work), is it possible

  • Want to make Monday as the first day of the week in GregorianCalendar. how?

    hi I need to know what day is the first of the month is. for example the 1st of Nov 2004 is Moday and 1st of Dec 2004 is saturday. I am using the GregorianCalendar: 1.  GregorianCalendar calendar = new GregorianCalendar(2004,11,1);    //set date to 1

  • Populating a collection with function results

    I am calculating some statistics and need to use a collection to store the results of several function so they can be used in a procedure. Example: PROCEDURE PRODUCTIVITY_INSERT(p_first_of_month IN DATE) AS BEGIN vc_FirstofMonth := p_first_of_month;

  • How to change the log file path in BEA tuxedo 6.5 client in Windows xp

    Hi, I am using BEA Tuxedo 6.5 client in windows xp. The log files are created in C: Kindly help me in changing the log file path and also i want to know where these configurations are set. Advance thanks !!! Regards Bunsim