InvalidPathException: Malformed input or input contains unmappable characters 中文名文件 linux存储失败

在将使用Java开发的系统通过Docker部署到Linux集群时,遇到InvalidPathException,原因是文件名包含无法映射的字符。问题出在文件编码上,特别是在处理中文文件名时。解决方案是通过设置JAVA_TOOL_OPTIONS环境变量,确保编码为UTF-8,如在KubeSphere中编辑yaml文件添加-Dfile.encoding=UTF-8和-Dsun.jnu.encoding=UTF-8。
摘要由CSDN通过智能技术生成

InvalidPathException: Malformed input or input contains unmappable characters 中文名文件 linux存储失败

使用java.nio.file.Path规范并解析路径,生成文件到本地,部分文件名带中文。提供对外下载文件接口,用于下载这些文件,下载后的文件要显示中文名。本地(windows)开发调试都OK。通过docker容器部署到开发环境(linux集群)后,调用文件生成接口,后台报错,报错信息如下:

java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: ????98?5??????????.doc
 	at sun.nio.fs.UnixPath.encode(UnixPath.java:147)
 	at sun.nio.fs.UnixPath.<init>(UnixPath.java:71)
 	at sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:281)
 	at java.io.File.toPath(File.java:2273)
 	at org.springframework.core.io.FileSystemResource.<init>(FileSystemResource.java:103)
 	at com.sx.system.controller.FileController.uploadFile$original$nBURC4QV(FileController.java:80)
 	at com.sx.system.controller.FileController.uploadFile$original$nBURC4QV$accessor$6dFBGKAE(FileController.java)
 	at com.sx.system.controller.FileController$auxiliary$hKLUE52q.call(Unknown Source)
 	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86)
 	at com.sx.system.controller.FileController.uploadFile(FileController.java)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.lang.reflect.Method.invoke(Method.java:498)
 	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)


解决办法 通过设置java环境参数来解决,若是docker部署的,有KubeSphere,则编辑yaml文件 添加即可

JAVA_TOOL_OPTIONS=‘-Dfile.encoding=“UTF-8” -Dsun.jnu.encoding=“UTF-8”’

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值