May 22, 2012 at 6:34 PM
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String filePath = "D:\\ratna\\RoseindiaHospital.zip";
String fileName = "RoseindiaHospital.zip";
FileInputStream fileToDownload = new FileInputStream(filePath);
ServletOutputStream output = response.getOutputStream();
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename="
+ fileName);
ByteArrayOutputStream output1 = new ByteArrayOutputStream();
int readBytes = 0;
byte[] buffer = new byte[10000];
while ((readBytes = fileToDownload.read(buffer, 0, 10000)) != -1) {
output.write(buffer, 0, readBytes);
output1.write(buffer, 0, readBytes);
}
output.flush();
output.close();
fileToDownload.close();
}
}
Description: -
Servletoutputstream is used for sending data to client in binary format.
It is retrieved via response.getOutputStream() function.
ServletOutputStream is an abstract class and servlet container implements it.
When you use character conversion and there is a lot of text then it is better
to use byte[] instead of String object.
ByteArrayOutputStream implements output stream and it contain data in form of byte array.For retrieving data you can use toByteArray() and toString() methods.
Related Tutorials/Questions & Answers:
Advertisements
Servletoutputstream size limit.Servletoutputstream size limit. What is the maximum size of
ServletOutputStream?
By default size is set to 10MB.You can increase
your message size maximum 2000000000 bytes.
That is size limit is 2000000000
conver byte array to ByteArrayOutputStreamconver byte array to ByteArrayOutputStream Sir
Can you please tell me how to convert the byte[] to
ByteArrayOutputStream;
One of my method will return the byte[] , i have to convert this byte array to
ByteArrayOutputStream Reading file into bytearrayoutputstreamHow to read file into
bytearrayoutputstream
This tutorial shows you how...
bytearrayoutputstream. This example code is very helpful
in learning the concept of byte... into
bytearrayoutputstream.
This example will teach you how you can read
Java ByteArrayOutputStream ExampleJava
ByteArrayOutputStream Example
In this section we will discuss about the Java IO Byte Streams
ByteArrayOutputStream.
ByteArrayOutputStream...() method does not put any effect on
the
ByteArrayOutputStream, methods can
Display PDF in browser - Struts();
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
PdfWriter.getInstance(document...");
response.setContentLength(baos.size());
ServletOutputStream out
JSP - Java BeginnersJSP how to use this code in jsp.here no response object.
ServletOutputStream outStream=response.getOutputStream();
response.setContentType("image/jpg");
response.setContentLength((int)fileLength
Exception - JSP-ServletException Hi,
I am Ragavendran.R.. I am using swiftchart for my chart application.. For this purpose, I am using
ServletOutputStream sos=response.getOutputStream(); in my JSP Page.
But, I am getting
Java writer outputstream
is used. And subclasses
ByteArrayOutputStream & FileOutputStream...;out = new
ByteArrayOutputStream();
Image Processing Java will be a
ByteArrayOutputStream (in memory)
ByteArrayOutputStream bos = new
ByteArrayOutputStream... the
ByteArrayOutputStream create a RenderedImage.
ByteArrayInputStream in = new
java - Java Beginners();
// Serialize to a byte array
ByteArrayOutputStream baos = new
ByteArrayOutputStream download - JSP-Servlet buf=null;
ServletOutputStream myOut=null;
try...;
//read from the file; write to the
ServletOutputStream
while...();
System.out.println("inside download servlet");
ServletOutputStream myOut
javas - JSP-Servlet{
ServletOutputStream out = response.getOutputStream();
String connectionURL
Java ServletResponse Interface data in
MIME body response then you have to use
ServletOutputStream
returned...() : This method returns a
ServletOutputStream suitable for writing binary data
Audio Level Meter running;
ByteArrayOutputStream out;
public Capture() {
super...() {
out = new
ByteArrayOutputStream();
running = true
Java writer api of
ByteArrayOutputStream
class object.ADS_TO_REPLACE_3
Syntax with examples for using the class:-
ByteArrayOutputStream out = new
ByteArrayOutputStream... PrintWriter();
Syntax for applying :-
ByteArrayOutputStream out = new
BLOB - SQL = null;
ServletOutputStream out = response.getOutputStream();
try
RequestDispatcher
ServletOutputStream or Writer
of the response object to write the information.ADS_TO_REPLACE_2
Post Message In servlet.
ServletOutputStream is a constructor. This constructor provides
an output stream for sending data to the client. A
ServletOutputStream object is
created using