使用url的Java fileinputstream

问题描述:

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

How to input in the fileinputstream, a file to url?

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

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 ? If it isn't, can you tell me what should I use instead of fileinputstream?

如果你想获得一个 InputStream 从URL检索数据,然后使用 URL.openStream 方法将返回 InputStream ,可以使用像任何其他 InputStream

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 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();