【发布时间】:2014-03-14 18:00:25
【问题描述】:
我想从 URL 下载图像文件。我的代码适用于互联网上图像的任何 URL,但我找不到从我自己的 PC 下载文件的方法,使用它的 URL,通过 wifi 热点连接到我的 android 手机。这甚至可能吗?如果是,请告诉我如何。
`URL url = new URL("file://192.168.43.198/f:/ur/demo.jpg");
URLConnection conection = url.openConnection();
conection.connect();
// getting file length
int lenghtOfFile = conection.getContentLength();
// input stream to read file - with 8k buffer
InputStream input = new BufferedInputStream(url.openStream(), 8192);
// Output stream to write file
OutputStream output = new FileOutputStream("/sdcard/downloadedfile.jpg");
byte data[] = new byte[1024];
while ((count = input.read(data)) != -1) {
total += count;
// writing data to file
output.write(data, 0, count);
}
`
【问题讨论】:
-
不! @AndyFaizan。我使用 ipconfig 确定了我的 PC 的 IP 地址。这种方法适用于其他使用 Sockets 的网络程序。但不是在这里。
-
好的。这个怎么样? stackoverflow.com/questions/9906021/…
-
您计算机的防火墙是否可能阻止访问?
标签: java android image url personal-hotspot