FTP 传输文件时编码 UTF-8 的问题

发布于 2024-08-09 13:43:40 字数 294 浏览 9 评论 0原文

我可以让我的应用程序使用 FTPClient Java 库通过 FTP 上传文件。

(我碰巧正在上传到 Oracle XML DB 存储库。)

一切上传都很好,除非 xml 文件中包含大引号。在这种情况下我收到错误: LPX-00200:无法从编码 UTF-8 转换为 UCS2

我可以使用 Windows CMD 行 FTP 工具上传我认为是相同的文件。我想知道 Windows CMD 行工具是否使用一些编码设置,也许我需要在 Java 代码中设置。

有人知道这方面的事情吗?谢谢!!

I am able to have my application upload files via FTP using the FTPClient Java library.

(I happen to be uploading to an Oracle XML DB repository.)

Everything uploads fine unless the xml file has curly quotes in it. In which case I get the error:
LPX-00200: could not convert from encoding UTF-8 to UCS2

I can upload what I believe to be the same file using the Windows CMD line FTP tool. I am wondering if there is some encoding setting that the windows CMD line tool uses that maybe I need to set in my Java code.

Anyone know stuff about this? Thanks!!

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

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

发布评论

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

评论(4

神魇的王 2024-08-16 13:43:40

我不知道该应用程序,但您可以尝试在 JVM 命令行上使用 -Dfile.encoding=UTF-8

I don't know that application but you could try to use -Dfile.encoding=UTF-8 on your JVM command line

つ可否回来 2024-08-16 13:43:40

不熟悉 Oracle XML DB 存储库 — 它们可以接受压缩上传吗?压缩或 gzip 压缩文件会节省资源并阻止使用中的任何 ASCII 文件类型自动检测。

Not familiar with Oracle XML DB repositories—can they accept compressed uploads? Zipping or gzipping your file would save resources and frustrate any ASCII file type autodetection in use.

轮廓§ 2024-08-16 13:43:40

在二进制中这个问题就消失了。

FTPClient.setType(FTPClient.TYPE_BINARY);

http://www.sauronsoftware.it/projects/ftp4j/manual.php# 3

In binary this problem goes away.

FTPClient.setType(FTPClient.TYPE_BINARY);

http://www.sauronsoftware.it/projects/ftp4j/manual.php#3

べ映画 2024-08-16 13:43:40

如果您的文件包含大引号,则它们位于 iso-8859-1 和 windows-1252 字符集中的高位位集范围内。在 UTF-8 中,这些字符通常在 UTF-8 中占用两个字节。

您很可能不小心使用这些编码之一而不是 UTF-8 对 xml 文件进行编码。这将导致转换错误,因为仅允许在多个 UTF-8 八位位组的序列中设置高位。

如果您使用的是 Windows,请在记事本中打开文件,然后尝试使用“另存为...”以 UTF-8 编码重新保存文档,然后上传更改后的文件。在 Unix 中,使用 iconv 或类似工具进行转换上传前从 iso-8859-1 转换为 UTF-8。

如果 XML 文档显式标记其编码,请确保使用正确的编码(例如 UTF-8)进行标记。在许多 xml 解析器中,您可以解析 iso-8859-1 或 windows-1252 字符集编码的 XML,只要它如此标记即可。

If your file contains curly quotes, they are in the high-order bit set range in iso-8859-1 and windows-1252 character sets. In UTF-8, those characters usually take two bytes in UTF-8.

It's quite possible that you've accidentally encoded the xml file in one of these encodings instead of UTF-8. That would result in a conversion error, because the high-order bit being set is only allowed in sequences of multiple UTF-8 octets.

If you're in Windows, open the file in Notepad and try re-saving the document using Save As... with the UTF-8 encoding, and upload the changed file.. In Unix, use iconv or a similar tool to convert from iso-8859-1 to UTF-8 before uploading.

If the XML document explicitly marks its encoding, make sure it's marked with the correct encoding (e.g. UTF-8). In many xml parsers, you can parse iso-8859-1 or windows-1252 character set encoded XML as long as it's marked as such.

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