csv文件不就是逗号分隔文件吗? 你把结果集IO输出到一个文件,字段与字段间插入逗号不就好了。需要考虑的是数据记录内容中如果有逗号的话要处理一下。

解决方案 »

  1.   

    一個小小的example,但要你作修改, because is part of program source... :-) public void convert() throws Exception{

    Iterator it_lst; PrintWriter out = null;
    FileOutputStream fos = null;
    OutputStreamWriter osw = null;
    StringBuffer sb = new StringBuffer();

    try { fos = new FileOutputStream(path + fileName, false);
    osw = new OutputStreamWriter(fos ,"UTF-8");
    out = new PrintWriter(osw);

    for(int i=0;i<3;i++){
    out.println("a"+String.valueOf(i)+","+"a"+String.valueOf(i+1));
    }

    }catch(Exception e2){
    String prgPath = "convert()"; LogFile.writeLog("");   
    throw new Exception("Write2Xml Error: IOException");

    }finally {
    try{
     
    if(paraLst != null){
    paraLst.clear();
    paraLst = null;
    }

    if(picLst != null){
    picLst.clear();
    picLst = null;
    } if(out != null){
    out.close();
    out = null;
    }

    if(fos != null){
    fos.close();
    fos = null;
    }

    if(osw != null){
    osw.close();
    osw = null;
    }

    if(sb!=null){
    sb = null;
    }

    }catch(IOException e){}
    }  
    }