views:

93

answers:

1

I have chosen nearly 200 files to write on a position automatically on a particular time. Created a separate job names in Quartz scheduler. The job will be triggered on a time. I can read the files only after all the files have been written. I could not read after one file is written. I have closed the FileWriter after one file written. What is the solution to access the file and read which have been written into the hard Disk

File f = new File(directory.getAbsolutePath() + File.separatorChar + context.getTrigger().getJobName() + ".sql"); System.out.println(f.getAbsolutePath()); fw = new FileWriter(f, true); System.out.println("DBname is " + scheduleInfo.get("dbName")); fw.append("CREATE DATABASE /!32312 IF NOT EXISTS/ " + scheduleInfo.get("dbName") + " /*!40100 DEFAULT CHARACTER SET latin1 */;\nUSE " + scheduleInfo.get("dbName") + ";\n"); ps1=con.prepareStatement(dbname_exist); ps1.setString(1,(String)scheduleInfo.get("dbName")); rs1=ps1.executeQuery(); if(rs1.next()) { backup_exits=true;

        }

        //if (br.readLine() == null||!backup_exits)
        if (br.readLine() == null){
            ps = con.prepareStatement(backup_data);
            ps.setString(1, (String) scheduleInfo.get("sch_id"));
            ps.executeUpdate();
            System.out.println("Failed to download file");
        }
        else {
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                fw.append(line + "\n");
            }
        }

               br.close();
               fw.close();
A: 

You need to make sure file outputstream is closed properly. Further close the file object instance as well

Fazal
*"close the file object instance as well"* how?
BalusC
I am sorry... I mean make sure you are not holding the reference to the file object. I am not sure if that causes an issue but I did experience issues with reading of the file unless I got rid of all references to the file object used for writing
Fazal