【问题标题】:Download file from computer connected via Wifi Hotspot using URL使用 URL 从通过 Wifi 热点连接的计算机下载文件
【发布时间】: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);
            }

 `

【问题讨论】:

标签: java android image url personal-hotspot


【解决方案1】:

您的计算机不会对“文件:”协议做出反应。在互联网上,您将使用“http:”,所以在这里也使用它。在你的电脑上安装一个网络服务器让它运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多