阿拉伯文件名转换为问号

发布于 2024-11-18 05:00:17 字数 360 浏览 3 评论 0原文

我有一个 Spring 应用程序,其形式之一是用来上传 Excel 文件的。

该应用程序将文件保存在硬盘上,并为用户提供再次下载的链接。

如果文件名用英文书写,则一切正常,但如果文件名包含阿拉伯字符,则文件阿拉伯字符将转换为问号。

很明显,问题与字符编码有关,但我无法准确检测问题出在哪里。

以下是系统结构和配置:

  • 操作系统:Centos
  • 应用服务器:Tomcat
  • server.xml 中的连接器配置

    [连接器端口=“8009”协议=“AJP/1.3”redirectPort=“8443”URIEncoding=“UTF-8”]

I have a spring application in one of the forms the use supposed to upload an excel file.

The application saves the file on the hard desk and provide a link to the user to download it again.

If the file name is written in English every thing goes OK but if the file name contains Arabic characters, the file Arabic characters are converted into question marks.

It is clear that the problem is related to character encoding but I can not detect where is the problem exactly.

Here is the system structure and the configurations:

  • Operating system : Centos
  • Application server : Tomcat
  • connector configs in server.xml

    [Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"]

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

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

发布评论

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

评论(4

§普罗旺斯的薰衣草 2024-11-25 05:00:17
  1. 你必须知道什么是阿拉伯字符的字符集。

  2. 如果您不知道,您可以尝试使用 UTF-16。

使用的代码如下:

// output stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();

// input stream
InputStream in = new FileInputSteam("filePath");

// reading buffer
byte[] buffer = new byte[1024];

// 1st read
int bytes = in.read(buffer, 0, buffer.length());

while(bytes != -1) {
   // write buffer
   bout.write(buffer);

   // re-load buffer
   bytes = in.read(buffer, bytes, buffer.length());
}

String yourText = bout.toString(Charset.forName("YOUR_CHARSET"));

// close stream or use JSE7 try-catch-with-resource
in.close();
bout.close();

尽情享受吧。

  1. You have to know what's char-set of Arabic character.

  2. If you don't know, you can try with UTF-16.

The code to use is following:

// output stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();

// input stream
InputStream in = new FileInputSteam("filePath");

// reading buffer
byte[] buffer = new byte[1024];

// 1st read
int bytes = in.read(buffer, 0, buffer.length());

while(bytes != -1) {
   // write buffer
   bout.write(buffer);

   // re-load buffer
   bytes = in.read(buffer, bytes, buffer.length());
}

String yourText = bout.toString(Charset.forName("YOUR_CHARSET"));

// close stream or use JSE7 try-catch-with-resource
in.close();
bout.close();

Enjoy yourself.

淡写薰衣草的香 2024-11-25 05:00:17

在 Windows 控制面板中,转到区域选项和区域选项。在“管理”选项卡中,选择“非 Unicode 程序的语言”,选择区域阿拉伯语言。

In Windows Control panel, go to Regional Option & in Administrative Tab, select in Langauge of Non Unicode programme, Select the regional Arabic Langauge.

回眸一笑 2024-11-25 05:00:17

我认为它的阿拉伯语语言不支持您的系统语言,所以请尝试这个

byte[] utf8Bytes = ("阿拉伯语字符串").getBytes("阿拉伯语");
参数 = new Object[]{new String(utf8Bytes,"UTF8")};
System.out.println(参数);

I think its arabic lang not support your system's language so try this.

byte[] utf8Bytes = ("Arabic String").getBytes("arabic");
argument = new Object[]{new String(utf8Bytes,"UTF8")};
System.out.println(argument);

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