本人菜鸟,遇到以下问题:
1、项目要求:从数据库中查询数据,然后上传到FTP2、现在我用的方式是用windows自带的定时任务,定时执行sql脚本,将查询的结果SPOOL到指定的文件夹下的自动生成的txt文件中,txt文件中显示的就是查询结果。以下是txt文件中显示的内容:
04525622121,张三,13329529555,20120111135947,20120111135947,1,,,04515622121,,0.10,1,1,4,0.10,1,,,,
04525622121,张四,13796851688,20120111135947,20120111135947,2,,,04515622121,,0.20,1,1,4,0.10,1,,,,
04525622121,张五,13234638555,20120111135947,20120111135947,1,,,04515622121,,0.10,1,1,4,0.10,1,,,,3、项目经理要求改进,不用windows定时任务。
   要求如下:从数据库查询的结果集,用File流,然后再上传到ftp我的问题:
1、我理解的是查到的结果集,用File流输出成txt文件。
那txt文件中显示的是什么?是二进制数还是跟我现在的形式一样就是正常的汉字?
我理解的对吗?不清楚用流干嘛?是生成文件,还是什么不生成文件把结果集保留到内存或别的地方2、为什么说这种方式比定时任务优化呢?我是菜鸟,没怎么接触过文件流。请高手指点。

解决方案 »

  1.   

    我不知道什么是定时任务,但是 文件流写数据到指定文件,是不是这个private void recordSocre(int total) {
    // TODO Auto-generated method stub
    BufferedWriter bw = null;
    try {
    bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("Socre.txt"),"utf-8"));
    StringBuilder str=new StringBuilder();
    long currenttime=System.currentTimeMillis();
    Date time=new Date();
    time.setTime(currenttime);
    DateFormat fmt=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String Time=fmt.format(time);
    str.append(user.getId()).append(":").append(user.getName()).append(":").append(total).append(":").append(Time);
    bw.write(str.toString());
    bw.newLine();
    } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }finally{
    try {
    bw.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }
      

  2.   

    从数据库读出来 然后写进txt