使用Quartz Scheduler自动使用FileWriter编写文件时出现问题

时间:2010-04-03 08:18:22

标签: java quartz-scheduler filewriter

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

文件f =新文件(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,(字符串)scheduleInfo.get( “DBNAME”));             RS1 = ps1.executeQuery();             如果(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();

1 个答案:

答案 0 :(得分:0)

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