Hi to all
I have a requirement in my app to download and upload.
I have done for uploading without any error.
For downloading there is some problem,file is downloading but its not readable.Suppose the download fiile is 50mb and after downloading when you check the size then also it says 50mb but its not readable.
Please tell me where do i have make changes.
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*" %>
<%@ page import= "java.io.*" %>
<%
try{
String txtFileNameVariable="movie.mp4";
String locationVariable="../webapps/y/";
String PathVariable="";
//txtFileNameVariable = request.getParameter("fileVariable");
//locationVariable = request.getParameter("locationVariable");
PathVariable = locationVariable+txtFileNameVariable;
BufferedReader bufferedReader = null;
try{
bufferedReader = new BufferedReader(new FileReader(PathVariable));
}
catch(FileNotFoundException fnfe){
fnfe.printStackTrace();
}
File f=new File(locationVariable, txtFileNameVariable);
String fileType = txtFileNameVariable.substring(txtFileNameVariable.indexOf(".")+1,txtFileNameVariable.length());
if (fileType.trim().equalsIgnoreCase("txt")) {
response.setContentType( "text/plain" );
} else if (fileType.trim().equalsIgnoreCase("doc")) {
response.setContentType( "application/msword" );
} else if (fileType.trim().equalsIgnoreCase("xls")) {
response.setContentType( "application/vnd.ms-excel" );
} else if (fileType.trim().equalsIgnoreCase("pdf")) {
response.setContentType( "application/pdf" );
} else {
response.setContentType( "application/octet-stream" );
}
String original_filename = txtFileNameVariable;
response.setHeader( "Content-Disposition", "attachment; filename=\"" + original_filename + "\"" );
try{
int anInt=0;
while((anInt=bufferedReader.read())!=-1)
out.write(anInt);
}catch(IOException ioe){
ioe.printStackTrace();
}
}catch(Exception e){
out.println("This is the Error " +e.getMessage());
}
%>