Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi, I have written a code to save an exe file from my server side to client's pc in C:\ drive.
But, I am getting error as like this:

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.OutOfMemoryError: Java heap space
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.


For my code:
HTML
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"  %> 
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% 
String fileName=getServletContext().getRealPath("jdk-6u20-windows-i586.exe"); 

File f=new File(fileName); 

InputStream in = new FileInputStream(f); 

BufferedInputStream bin = new BufferedInputStream(in); 

DataInputStream din = new DataInputStream(bin); 
StringBuffer sb=new StringBuffer(); 
while(din.available()>0) 
    { 
    sb.append(din.readByte()); 
    } 

try {    
    PrintWriter pw = new PrintWriter(new FileOutputStream("c:/jdk-6u20-windows-i586.exe"));// save file 
    pw.println(sb.toString()); 
    pw.close(); 
} catch(IOException e) { 
   e.getMessage(); 
} 
          
in.close(); 
bin.close(); 
din.close(); 
%> 
    </body>
</html>

Please help me to solve this problem. And if I want to add a progress bar to display count % for downloading file than what I have to do for this in my code. Can you help me brother?
Posted

1 solution

No Popular browser will give you access to Client's local file system
In this case you can provide a link to file by putting it in your project folder or GlassFish Server folder
or else you case use a signed applet
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900