从Linux下载文件是空的

时间:2016-04-20 19:34:35

标签: java linux primefaces websphere-7

我试图下载一个文件,我刚刚从服务器(Linux)文件中的路径创建一个CSV,它有两行,当我尝试下载它时,它被下载但是它已经下载了空,如果文件很大,它确实完成了,

你有什么想法吗?我使用的是primefaces p:download component。

File f = new File(dir.trim());
FileWriter filWrite = new FileWriter(f, Boolean.TRUE);
        BufferedWriter bw = new BufferedWriter(filWrite);

        while(query.next()){
            // cada 50,000 crea un nuevo txt
            if(i==50000){
                dir = rutaDestino+""+prefijoArchivo+"_"+count+".csv";
                f = new File(dir.trim());// crea archivo
                filWrite = new FileWriter(f, Boolean.TRUE);
                bw.close();
                bw = new BufferedWriter(filWrite);
                i=1;
                count++;                    
            }               
            for(j=1;j<=numeroColumnas;j++){
                bw.append(query.getString(j));
                if (j<numeroColumnas){  
                  bw.append("||");
                }
            }               
            //bw.newLine();
            bw.append("\n");
        i++;
        }
        bw.close();

然后我下载这样的文件:

private DefaultStreamedContent download;

public void prepDownload(String path) throws Exception {
    try {
        File file = new File(path);
        InputStream input = new FileInputStream(file);
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(file.getName()), file.getName()));
    } catch (Exception e) {
        JsfUtil.showFacesMsg(
                e,
                "Error en Clase GestionResultadosMB metodo prepDownload",
                "sysErrMsg", FacesMessage.SEVERITY_FATAL);
    }
}

0 个答案:

没有答案