Reputation: 5313
i have a jsp project , in my project i want to download a txt file from the location.The code really worked but the conent of the file is actually jsp index page content, i don't know how is this happened.
String filename = "Teste.txt";
String filepath = "D:\\Online Secure File Transfer System\\project";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename);
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
Upvotes: 0
Views: 733
Reputation: 1956
I think problem with your file path , do not append string
String filename = "Teste.txt";
String filepath = "D:\\Online Secure File Transfer System\\project\\Teste.txt";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath);
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
Upvotes: 1