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,190 points
753 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
• 59,230 points
584 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
• 59,230 points
13,069 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,190 points
958 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
• 59,230 points
1,844 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,920 points
17,227 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,620 points
1,539 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
17,965 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
• 19,610 points
1,183 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
979 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
5,657 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP