我选择了将近200个文件在特定时间自动写入位置。在Quartz Scheduler中创建了一个单独的作业名称。该作业将在某个时间触发。只有写入所有文件后,我才能读取文件。写入一个文件后,我无法读取。写入一个文件后,我已经关闭了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();
我选择了将近200个文件在特定时间自动写入位置。在Quartz Scheduler中创建了一个单独的作业名称。该作业将在某个时间触发。我可以读取文件...
您需要确保文件输出流正确关闭。也进一步关闭文件对象实例