0

我选择了近 200 个文件在特定时间自动写入某个位置。在 Quartz 调度程序中创建了一个单独的作业名称。作业将被触发一次。只有在所有文件都被写入后,我才能读取文件。写入一个文件后我无法阅读。写入一个文件后,我关闭了 FileWriter。访问已写入硬盘的文件并读取的解决方案是什么

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

1 回答 1

0

您需要确保正确关闭文件输出流。进一步关闭文件对象实例

于 2010-04-03T20:47:06.567 回答