4 Replies Latest reply: Dec 10, 2008 6:01 AM by 807589 RSS

    Opening CSV file in ReadOnly while writing data to it.

      I am writing huge ammount of data in CSV file. If i open the excel file in 'Read only' or 'Notify' mode, my java program gives Exception as

      java.io.IOException: The process cannot access the file because another process has locked a portion of the file

      This should be case as opening excel is not locking any thing for writing.

      What i am doing is some thing like this,

      String wd = System.getProperty("user.dir");
      JFileChooser fc = new JFileChooser(wd);
      int rc = fc.showDialog(null, "Save File As");
                     if (rc == JFileChooser.APPROVE_OPTION)
                          File file = fc.getSelectedFile();
                          String strNewFileName = file.getAbsolutePath() + "." + "csv";
                          File newfile = new File(strNewFileName);
                          try {
                               Writer output = new BufferedWriter(new FileWriter(newfile));
                               // fetch data from database

      What should be cause for this?

      Appriciate your help..

      Edited by: charuta on Dec 10, 2008 3:40 AM