Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将内存中的图像保存到url_Android_Image - Fatal编程技术网

Android 将内存中的图像保存到url

Android 将内存中的图像保存到url,android,image,Android,Image,我正在使用此代码保存图像,我不确定它是否正确 public String baixarImagem(String urlC, String nomeImagem) throws MalformedURLException { URL url = new URL(urlC); InputStream input = null; FileOutputStream output = null; try { String outputName = no

我正在使用此代码保存图像,我不确定它是否正确

public String baixarImagem(String urlC, String nomeImagem) throws MalformedURLException {
    URL url = new URL(urlC);

    InputStream input = null;
    FileOutputStream output = null;

    try {
        String outputName = nomeImagem + ".jpg";

        input = url.openConnection().getInputStream();
        output = context.openFileOutput(outputName, Context.MODE_PRIVATE);

        int read;
        byte[] data = new byte[1024];
        while ((read = input.read(data)) != -1)
            output.write(data, 0, read);

        return outputName;

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (output != null)
                output.close();

            if (input != null)
                input.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}

有人能告诉我他是否正确。我希望恢复已保存的图像并在列表视图中显示我不知道如何执行此操作,如果有人知道,请告诉我

您是否确实尝试过此代码?它按你想要的方式工作了吗?如果您没有向我们提供您在该代码中遇到的问题,我们将无法真正提供帮助。若要使用此代码保存,我需要知道如何检索此代码的已保存图像若要使用此代码保存,我需要知道如何检索此代码的已保存图像