Java 如何解决apache常见的vfs URL编码错误

Java 如何解决apache常见的vfs URL编码错误,java,ftp,encode,Java,Ftp,Encode,我使用Apache common vfs执行FTP操作,但如果URL中有中文,就会出现一些奇怪的问题 我的代码是这样的: String path = "ftp://user:pwd@localhost:21/foo/泰聚/说愚惭/询回撼舆/米曲浓树疚/窃窃尿押疆腔/bar"; String encodedPath = new String(path.getBytes("UTF-8"), "ISO-8859-1"); manager = VFS.getManager(); FileObject f

我使用Apache common vfs执行FTP操作,但如果URL中有中文,就会出现一些奇怪的问题

我的代码是这样的:

String path = "ftp://user:pwd@localhost:21/foo/泰聚/说愚惭/询回撼舆/米曲浓树疚/窃窃尿押疆腔/bar";
String encodedPath = new String(path.getBytes("UTF-8"), "ISO-8859-1");
manager = VFS.getManager();
FileObject fo = manager.resolveFile(encodedPath);
fo.createFolder();
Caused by: org.apache.commons.vfs2.FileSystemException: Could not create FTP directory "ftp://test:***@localhost/test/æ°å¸/éä¸ç»/å¡èåä»»/åªæ²é¡¹æ å/侩èæè¨ç­ç¾".
例外情况如下:

String path = "ftp://user:pwd@localhost:21/foo/泰聚/说愚惭/询回撼舆/米曲浓树疚/窃窃尿押疆腔/bar";
String encodedPath = new String(path.getBytes("UTF-8"), "ISO-8859-1");
manager = VFS.getManager();
FileObject fo = manager.resolveFile(encodedPath);
fo.createFolder();
Caused by: org.apache.commons.vfs2.FileSystemException: Could not create FTP directory "ftp://test:***@localhost/test/æ°å¸/éä¸ç»/å¡èåä»»/åªæ²é¡¹æ å/侩èæè¨ç­ç¾".
此异常并非每次都出现,它似乎是由于某些单词的编码所致