使用url的Java fileinputstream [英] Java fileinputstream using with url

查看:1008
本文介绍了使用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?

推荐答案

如果你想获得一个< a href =http://download.oracle.com/javase/6/docs/api/java/io/InputStream.html\"rel =noreferrer> 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();

这篇关于使用url的Java fileinputstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆