如何处理文件/文件夹路径中的不同语言
我编写了一个应用程序,它采用文件夹路径并执行一些操作。但是,如果文件夹路径包含英语以外的语言字符,则它不起作用。它仅支持英文字符。如何处理这个问题?
I have written an application which takes folder path and perform some operation. But if folder path contains characters of language other than English then it is not working. It only support English characters. How to handle this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理论上它应该有效。实际上,在大多数情况下,这是将参数从 shell 传递到 java 应用程序的问题。尝试验证其是否正常工作:从命令提示符完全按照您正在执行的操作运行应用程序,但使用远程调试。在您正在读取参数的代码中创建断点并查看值是什么。我相信这个阶段的价值已经被破坏了。如果您使用的是 Windows,这是一个典型的问题。
在这种情况下,您必须将系统配置为在命令提示符中正确支持 unicode 字符。
如果从命令行正确读取路径,请尝试继续调试并查看哪里损坏。检查您使用的是哪种分隔符。避免同时使用 / 和 \,而是使用 File.separator。
Theoretically it should work. Practically in most cases it is a problem of passing parameters from shell to java application. Try to verify that this works correctly: run application from command prompt exactly as you are doing but with remote debugging. Create breakpoint in your code where you are reading the parameter and see what is the value. I believe that the value is corrupted at this phase. This is a typical problem if you are on windows.
In this case you have to configure your system to support unicode characters in command prompt correctly.
If the path is read correctly from command line try to continue debugging and see where it is broken. Check which separator are you using. Avoid using both / and \, use File.separator instead.