Return String in DataHandler

后端 未结 1 1488
长发绾君心
长发绾君心 2021-01-19 03:48

I\'ve created a web service in Java that returns a DataHandler. This has to be able to return a File, which works fine. But it should

相关标签:
1条回答
  • 2021-01-19 04:04

    JavaMail has a ByteArrayDataSource that you can use for this purpose:

    DataSource ds = new ByteArrayDataSource(theString, "text/plain; charset=UTF-8");
    DataHandler handler = new DataHandler(ds);
    

    The charset in the mime type determines what encoding it will use to convert the string to bytes.

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