Is there any way to write content of Java InputStream to an OutputStream?

0 votes
If an InputStream in and an OutputStream out is given. Is there a way to write content from in to out?
Jul 6, 2018 in Java by Akrati
• 3,150 points
107 views

1 answer to this question.

0 votes

org.apache.commons.io.IOUtils from Apache has a method called copy(InputStream,OutputStream).which does exactly what you're looking for

InputStream in;
OutputStream out;
IOUtils.copy(in,out);
in.close();
out.close();
answered Jul 6, 2018 by sharth
• 3,370 points

Related Questions In Java

0 votes
2 answers

Is there any way to declare an array in-line?

Another way to do that, if you ...READ MORE

answered Aug 30, 2019 in Java by Sirajul
• 48,530 points
41 views
0 votes
2 answers

In Java, what is the best way to determine the size of an object?

I happened to find a java class "jdk.nashorn.internal.ir.debug.ObjectSizeCalculator", ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 48,530 points
480 views
0 votes
1 answer

What is an efficient way to implement a singleton pattern in Java?

Use an enum: public enum Foo { ...READ MORE

answered Jul 6, 2018 in Java by Akrati
• 3,150 points
131 views
0 votes
2 answers

What is the easiest way to iterate through the characters of a string in Java?

There are two approaches to this: for(int i ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 48,530 points
139 views
0 votes
2 answers

How do I read and convert an InputStream object to string type?

You can also use Java Standard Library ...READ MORE

answered Jul 17, 2018 in Java by Sushmita
• 6,890 points
6,017 views
0 votes
1 answer

How to read and write on an excel files?

Follow these steps: Write: public class User { ...READ MORE

answered May 15, 2018 in Java by Rishabh
• 3,560 points
335 views
0 votes
2 answers

Scanner is skipping nextLine() after using next() or nextFoo()?

use input.nextLine(); after your nextInt() function for example:- input.nextInt(); ...READ MORE

answered May 11, 2019 in Java by Sourav Dangi
1,869 views
0 votes
2 answers

Reading an InputStream & coverting it into a String in Java?

Apache Commons allows: String myString = IOUtils.toString(myInputStream, "UTF-8"); And ...READ MORE

answered Aug 30, 2019 in Java by Karan
• 9,300 points
126 views
0 votes
1 answer

How to get the IP address of the machine using Java?

One approach is to use NetworkInterface.getNetworkInterfaces() to get all ...READ MORE

answered Jun 25, 2018 in Java by sharth
• 3,370 points
50 views
0 votes
1 answer

How to count the number of occurrences of an element in a List?

We can use the static frequency() method. int ...READ MORE

answered Aug 21, 2018 in Java by sharth
• 3,370 points
81 views