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
59 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
1 answer

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

You can probably refer this:  m(new String[]{"hi", "hello", ...READ MORE

answered Jul 10, 2018 in Java by Daisy
• 8,040 points
14 views
0 votes
1 answer

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

Please check the below code to arrive ...READ MORE

answered Nov 21, 2018 in Java by Frankie
• 9,810 points
64 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
69 views
0 votes
1 answer

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

The below code seems the easiest to ...READ MORE

answered Jul 13, 2018 in Java by scarlett
• 1,280 points
39 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,840 points
2,269 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,520 points
172 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
615 views
0 votes
1 answer

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

Use Apache commons IOUtils and copy the ...READ MORE

answered Oct 8, 2018 in Java by DataKing99
• 8,100 points
47 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
31 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
40 views