title: BufferedWriter is not writing to ByteArrayOutputStream
body: <p>I want to convert an input stream to byte array. I know I can use IOUtils from commons-io. But I am practicing some basics in java io. I read an xml file using BufferedReader and tried writing it to a ByteArrayOutputStream using BufferedWriter. But its not working.</p>
  
  <p>When I write directly to the ByteArrayOutputStream its working. Whats wrong in my code?</p>
  
  <pre><code>try (InputStream inputStream = getClass().getResourceAsStream(
                  "/productInventory.xml");
                  ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
                  BufferedWriter bufferedWriter = new BufferedWriter(
                          new OutputStreamWriter(arrayOutputStream));
                  BufferedReader bufferedReader = new BufferedReader(
                          new InputStreamReader(inputStream));) {
              String line = "";
              while ((line = bufferedReader.readLine()) != null) {
  
                  bufferedWriter.write(line);
              }
              System.out.println(arrayOutputStream.size());
          } catch (IOException e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p>When I include below line in the loop its working</p>
  
  <pre><code>arrayOutputStream.write(line.getBytes(), 0, line.getBytes().length);
  </code></pre>
  
  <p>What is wrong while using BufferedWriter?</p>