如何将HTTP请求主体写入Java Web App中的文件?

时间:2016-01-19 14:09:27

标签: java unicode utf-8 io

这是我的代码:

USER_ID       START_DATE       END_DATE
1             2015-08-12       2015-12-08
2             2015-02-25       2015-06-01
3             2015-04-14       2015-09-21
4             2015-12-20       2016-01-13

当我收到这样的HTTP请求时:

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    final ServletInputStream inputStream = req.getInputStream();
    int read;
    File file = new File("koray.txt");
    final FileOutputStream fileOutputStream = new FileOutputStream(file);
    while ((read = inputStream.read()) != -1) {
        fileOutputStream.write(read);
    }
    fileOutputStream.flush();
    fileOutputStream.close();
}

在koray.txt中我会看到:

beer-characteristics=ğ

好吧c49f似乎是'ğ'的utf-8十六进制值,但为什么我看到文件中的十六进制值,而不是'ğ'本身?

编辑:这不起作用:

beer-characteristics=%C4%9F

1 个答案:

答案 0 :(得分:0)

用以下内容包装您的输入流:

NSStringFromX()

然后在utf-8中从缓冲读取器读取数据。