java中ASCII到UTF-8的转换

发布于 2024-11-06 20:57:52 字数 121 浏览 0 评论 0原文

我有一个问题,我使用 .CSV 文件格式上传数据,并由 java 类读取。我将存储在 db 中。现在没问题了,但是当我从 db 读取数据时,数据包含一些特殊字符。

所以请你在这里帮助我

提前谢谢。

i have a problem which i uploaded data using .CSV file format and it read by java class.and i would be store in db.upto now no problem,but when i read the data from db then data contains some special characters.

so please could you help me here

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小沫ゞ 2024-11-13 20:57:52

ASCII-7 与 UTF-8 兼容。您无需执行任何操作即可将 ASCII-7 转换为 UTF-8(但反之则不起作用)

ASCII-7 is compatible with UTF-8. There is nothing you need to do turn turn ASCII-7 into UTF-8 (but it doesn't work the other way)

最美不过初阳 2024-11-13 20:57:52

这是一篇你真正应该阅读的文章。

每个软件开发人员绝对必须了解 Unicode 和字符集的绝对最低限度(没有任何借口!)

接下来,回答您的问题:

  • 读取使用 UTF-8 编码的文件,请使用 BufferedReader

    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
    
  • 写入文件使用 UTF-8 编码使用 BufferedWriter

    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
    

确保通过套接字的数据传输正确。

This is an article you should really read.

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Next, to answer your question:

  • To Read a file encoded with UTF-8, use a BufferedReader:

    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
    
  • To Write a file encoded with UTF-8 use a BufferedWriter:

    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
    

Make sure that the transmittion of the data through the sockets goes correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文