Java servlet and IO: Create a file without saving to disk and sending it to the user

前端 未结 1 1021
臣服心动
臣服心动 2020-12-31 12:41

I`m hoping can help me out with a file creation/response question. I know how to create and save a file. I know how to send that file back to the user via a ServletOutputStr

相关标签:
1条回答
  • 2020-12-31 13:15

    You don't need to save off a file, just use a ByteArray stream, try something like this:

    inputStream = new ByteArrayInputStream(text.getBytes());

    Or, even simpler, just do:

    stream.write(text.getBytes());

    As cHao suggests, use text.getBytes("UTF-8") or something similar to specify a charset other than the system default. The list of available charsets is available in the API docs for Charset.

    0 讨论(0)
提交回复
热议问题