简体   繁体   English

java.io.file将//变成/?

[英]java.io.file is turning // into /?

I'd like to instantiate a file from an FTP path like: 我想从FTP路径实例化一个文件,例如:

java.io.File file = new File("ftp://"+"path/to/file");

But when I try to get the fileInputStream of this file: 但是当我尝试获取此文件的fileInputStream时:

FileInputStream in = new FileInputStream(file);

I get a java.io.FileNotFoundException. 我得到一个java.io.FileNotFoundException。

When I debug, I can see that during the instantiation of the file object, the path turns to "ftp:/path/to/file" -- with ONE slash ==> which throws the exception since he needs double slashes "//" after "ftp:" to locate the file into the FTP server. 当我调试时,我可以看到在文件对象的实例化过程中,路径变为“ ftp:/ path / to / file”-一个斜杠 ==>会引发异常,因为他需要双斜杠“ //在“ ftp:”之后,将文件定位到FTP服务器。

How can I make the path contain double slashes ? 如何使路径包含双斜杠?

Thank you 谢谢

You need to use a FTP client, such as Apache Commons Net . 您需要使用FTP客户端,例如Apache Commons Net

The File API available in the JDK cannot connect to a FTP server out of the box. JDK中可用的File API无法直接连接到FTP服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM