2014-02-15 78 views
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); 
      } 

` 
+0

這是否有幫助:http://stackoverflow.com/questions/6561317/get-ip-from-wifi-hotspot-in-android – AndyFaizan

+0

沒有! @AndyFaizan。我使用ipconfig確定了我的PC的IP地址。這種方法適用於使用套接字的其他網絡程序。但不是在這個。 – Shashank

+0

好的。這個怎麼樣? http://stackoverflow.com/questions/9906021/getting-the-ip-address-of-client-or-getting-the-informationssid-of-clients-con – AndyFaizan

回答

0

您的計算機不會對'file:'協議作出反應。在互聯網上你會使用'http:',所以在這裏使用。在你的電腦上安裝一個網絡服務器讓它工作。

相關問題