简体   繁体   English

使用url的Java fileinputstream

[英]Java fileinputstream using with url

How to input in the fileinputstream, a file to url? 如何在fileinputstream中输入一个文件到url?

I enter the url in the Fileinputstream, but the output of the URL is wrong, because the link slashes are turned backwards like - from / to \\ and the double slashes // are \\ only one slash and backwards.Is there a way with the fileinputstream to do that ? 我输入了Fileinputstream中的url,但是URL的输出是错误的,因为链接斜杠向后转向 - 从/到\\和双斜杠//只有一个斜杠和向后。有一种方法fileinputstream要做到这一点? If it isn't, can you tell me what should I use instead of fileinputstream? 如果不是,你能告诉我应该使用什么而不是fileinputstream吗?

If you want to obtain an InputStream to retrieve data from a URL, then using the URL.openStream method will return an InputStream , which can be used like any other InputStream . 如果要获取InputStream以从URL检索数据,则使用URL.openStream方法将返回InputStream ,可以像任何其他InputStream一样使用它。

For example, 例如,

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 can be initialized with either a path name or a file object. 可以使用路径名或文件对象初始化FileInputStream。

If supplying a path name you should only need to convert any back slashes \\ to double backslashes \\ 如果提供一个路径名,你应该只需要转换任何反斜线 \\反斜杠加倍\\

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

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