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