Return String in DataHandler

后端 未结 1 1476
长发绾君心
长发绾君心 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)
提交回复
热议问题