This discussion is archived
1 Reply Latest reply: Sep 8, 2010 8:46 AM by 800725 RSS

Problem transferring file from UNIX to Windows

800725 Newbie
Currently Being Moderated
Hi

I have a csv file in a UNIX path. When I attempt to download the file from a windows client (using IE 7 if it helps) using the following code, all I get is a set of junk characters (null ASCII to be specific). The file name and file size are coming properly but not the content. The code is as below:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = new FileInputStream(new File(fileToOpen));
byte[] buffer = new byte[1000];
int bytesRead = 0;

while ((bytesRead = stream.read(buffer, 0, 1000)) != -1) {
baos.write(buffer, 0, bytesRead);
}

//close the stream
stream.close();
byte[] content = baos.toByteArray();

response.setHeader("Content-Type","application/csv");
response.setContentLength(content.length);

response.setHeader("Content-Disposition", "attachment;filename="+fileName+"");

ServletOutputStream out= response.getOutputStream();
out.write(content);
out.flush();
out.close();
Anyone with an idea how to solve this? I have tried using character streams too using PrintWriter but din't have any luck with that either.

Thanks in advance as I'm sure someone here will have a solution to this :)

Regards
coolprosu