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
67 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,320 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 in Java by Sirajul
• 25,420 points
22 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 in Java by Sirajul
• 25,420 points
109 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
86 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 in Java by Sirajul
• 25,420 points
61 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,880 points
3,340 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,540 points
211 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 in Java by Sourav Dangi
887 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 in Java by Karan
• 1,900 points
63 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,320 points
37 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,320 points
46 views