Download and save file in java

Download and save file in java

download and save file in java

Java: How to save / download a file available at a particular URL location in Internet? December 20, 2011 · by Singaram Subramanian · in Coding tips, Java · 1. There are multiple ways to download a file using Java code. from a URL directly into the intended file without needing to save the bytes in application memory. Downloading files in Selenium WebDriver Using Java Note: Save the file with.​exe extension and run using command e.g Runtime. download and save file in java

Downloading file with option for users to save or open the file

  • Post ReplyBookmark TopicWatch Topic
  • New Topic
posted 16 years ago
I know the syntax of downloading any file from server to client machine using <a href="folename">click</a> this code directly gives a save file option but how to give a option to user to open it or save it using response.setContentType("text/csv"); option please try to explain with an example code.
Regards
Nilesh B Chokhadia
posted 16 years ago
Instead of setting the content type to "text/csv", try "octet/stream".
posted 16 years ago
Thank you for replying
when i make <%response.setContentType("octet/stream");%>
while loading jsp page it gives me the option of save open or cacel for jsp file I want this option for downloading file like execel,word,wav format file so where can I place this <%response.setContentType("octet/stream");%>
should i palce with
<a href="ShiftScheduled.xls" ....onCclick="<%response.setContentType("octet/stream");%>">shift</a> but it never works help me.
regards
Nilesh
posted 16 years ago
The JSP below will take a file named "test.doc" and stream it back to the web browser as an octet/stream (a bunch o unknown bytes). This forces the browser to open the "Open or Save As" dialog.
=========================================================================
<%@ page import="javax.servlet.*,java.io.*" %><%@ page contentType="octet/stream" %><%
response.addHeader("Content-Disposition", "filename=test.doc");
File f = new File("c:\test.doc"));
FileInputStream fis = new FileInputStream(f);
byte[] buffer = new byte[(int)f.length()];
fis.read(buffer,0,(int)f.length());
fis.close();
ServletOutputStream os = response.getOutputStream();
os.write(buffer);
os.close();
%>
reply
    Bookmark TopicWatch Topic
  • New Topic
current ranch time (not your local time) is Dec 04, 2020 02:59:46
Источник: [https://torrent-igruha.org/3551-portal.html]

Download and save file in java

3 thoughts to “Download and save file in java”

Leave a Reply

Your email address will not be published. Required fields are marked *