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 ?
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"))
The standard Java class libraries offer no way to wrap a Reader
as an InputStream
, but the following SO question and its answers offer some solutions. Be careful to read the fine-print!
How to convert a Reader to InputStream and a Writer to OutputStream?
However, it is simpler to just stick with what you have got, (if this is just unit test code ... as it appears to be), or to replace the StringInputStream
with a ByteArrayInputStream
as described by @Thilo's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With