ByteArrayOutputStream problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dzenanz
    New Member
    • Feb 2008
    • 45

    ByteArrayOutputStream problem

    Code:
    ByteArrayOutputStream smsbuf = new ByteArrayOutputStream();
    OutputStreamWriter out = new OutputStreamWriter(smsbuf, Charset.forName("8859_1"));
    out.write("this gets lost");
    ByteArrayInputStream smsinbuf = new ByteArrayInputStream(smsbuf.toByteArray());
    BufferedReader in = new BufferedReader(new InputStreamReader(smsinbuf, Charset.forName("8859_1")));
    Problem: in is empty, as is the underlying buffer. smsbuf.toByteAr ray() returns empty array! What am I doing wrong?

    This is one of the failed attempts to check convertibility to ASCII (see my other post )
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Try to flush your 'out' writer before you try to get the byte array.

    kind regards,

    Jos

    Comment

    • dzenanz
      New Member
      • Feb 2008
      • 45

      #3
      Yes, that must be it.

      Thanks

      Comment

      Working...