我有一个旧项目,我很迷茫。
我正在从FTP下载文件,但是它没有完全下载,而是在完全完成之前生成的。
我每次下载的大小都不一样,比实际大小差
FTPClient ftpClient = new FTPClient();
ftpClient.connect("xxxx");
ftpClient.login("xxx", "xxxx");
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.changeWorkingDirectory("/");
InputStream in = ftpClient.retrieveFileStream(consentimiento.getRutaFichero());
BufferedInputStream objLector = new BufferedInputStream(in);
FacesContext objContexto = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) objContexto.getExternalContext().getResponse();
String contentType = Utilidades.obtenerTipoDocumento("wav");
response.setContentType(contentType);
response.setContentLength(in.available());
response.setHeader("Content-disposition", "attachment; filename=\"" + consentimiento.getNombreFichero() + "\"");
BufferedOutputStream objGrabador = new BufferedOutputStream(response.getOutputStream());
// Traspasar el contenido del fichero al objeto response
for (int data; (data = objLector.read()) != -1;) {
objGrabador.write(data);
}
objGrabador.flush();
objGrabador.close();
objLector.close();
objContexto.responseComplete();