Search code examples
javastringreader

How to replace StringBufferInputStream with StringReader?


Using JNLP, I have this line :

File_Save_Service.saveFileDialog(null,null,new StringBufferInputStream("testing"),null);

How to replace StringBufferInputStream with StringReader in this line ? The API for StringBufferInputStream says better use StringReader, but how to convert between different types ?


Solution

  • FileSaveService.saveFileDialog takes an InputStream, not a Reader (because it wants binary data, not character data).

    StringBufferInputStream is deprecated because it does not convert characters into bytes properly.

    You can use ByteArrayInputStream instead:

    new ByteArrayInputStream("the string".getBytes("UTF-8"))