Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can save your file anywhere on your server, you just need to know the path.</p> <blockquote> <p>how i direct it as output stream?</p> </blockquote> <p>Here is a code snippet that can help you.</p> <pre><code>File fileOnServer = new File("Hello.txt"); // Give full path where your file is located byte[] file = new byte[(int) fileOnServer.length()]; FileInputStream fileInputStream = new FileInputStream(fileOnServer); fileInputStream.read(file); int contentLength = (int) file.length; response.setContentLength(contentLength); response.setHeader("Content-Disposition", "attachment; filename=\"Hello.txt\""); out = response.getOutputStream(); int bytesWritten = 0; byte[] buffer = new byte[1024]; while (bytesWritten &lt; contentLength) { int bytes = Math.min(1024, contentLength - bytesWritten); System.arraycopy(file, bytesWritten, buffer, 0, bytes); if (bytes &gt; 0) { out.write(buffer, 0, bytes); bytesWritten += bytes; } else if (bytes &lt; 0); } </code></pre> <blockquote> <p>get download to user end?</p> </blockquote> <p>Well you can add ClickHandler on a Button on your client side and override <code>onClick</code> method.</p> <pre><code>public void onClick(ClickEvent event) { Window.open("UrlToYourServelet", "_blank", "null"); } </code></pre> <p>Hope this helps!</p> <p><strong>EDIT</strong></p> <p>I have found a solution. You can upload the file at any free file hosting site like <a href="http://www.4shared.com/" rel="nofollow">this</a>. This site provides a URL for every uploaded file. So in your servelet, make a HTTP request to the URL and download the file in <code>byte[]</code> and write it on outputStream as shown in the code above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload