使用 Quartz Scheduler 自动使用 FileWriter 写入文件的问题

发布于 2024-08-27 12:39:32 字数 1226 浏览 11 评论 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();

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神回复 2024-09-03 12:39:32

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文