0
我想从URL下载图像文件。我的代码适用于互联网上图像的任何URL,但我无法找到一种方法从我自己的PC下载文件,使用它的URL,通过WiFi热点连接到我的android手机。这甚至有可能吗?如果是,请告诉我如何。从使用URL连接的计算机通过Wifi Hotspot下载文件
`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);
}
`
这是否有帮助:http://stackoverflow.com/questions/6561317/get-ip-from-wifi-hotspot-in-android – AndyFaizan
没有! @AndyFaizan。我使用ipconfig确定了我的PC的IP地址。这种方法适用于使用套接字的其他网络程序。但不是在这个。 – Shashank
好的。这个怎么样? http://stackoverflow.com/questions/9906021/getting-the-ip-address-of-client-or-getting-the-informationssid-of-clients-con – AndyFaizan