简体   繁体   中英

Problem with Writing files using FileWriter automatically with Quartz Scheduler

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();

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM