0

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);
            }

 `
4

1 に答える 1