Problem with Writing files using FileWriter automatically with Quartz Scheduler

By : Jeeva

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( { 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"));
            System.out.println("Failed to download file");
        else {
            while ((line = br.readLine()) != null) {
                fw.append(line + "\n");

By : Jeeva


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

By : Fazal

This video can help you solving your question :)
By: admin