使用 Quartz Scheduler 自动使用 FileWriter 写入文件的问题
我选择了近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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要确保文件输出流已正确关闭。进一步关闭文件对象实例
You need to make sure file outputstream is closed properly. Further close the file object instance as well