使用url的Java fileinputstream

如何在fileinputstream中输入一个文件到url?

我输入了Fileinputstream中的url,但是URL的输出是错误的,因为链接斜杠向后转,如 – 从/到\和双斜杠//只有一个斜杠和向后。有一种方法fileinputstream要做到这一点? 如果不是,你能告诉我应该使用什么而不是fileinputstream吗?

如果要获取InputStream以从URL检索数据,则使用URL.openStream方法将返回一个InputStream ,可以像任何其他InputStream一样使用它。

例如,

 InputStream is; // if we were getting data from a file, we might use: is = new FileInputStream("/path/to/file"); // or, from a URL, then retrieve an InputStream from a URL is = new URL("http://google.com/").openStream(); 

可以使用路径名或文件对象初始化FileInputStream。

如果提供路径名,则只需要将任何反斜杠转换为双反斜杠\