Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.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
Java 是否在应用程序文件夹中保存图像?_Java_Android_Image_Gallery - Fatal编程技术网

Java 是否在应用程序文件夹中保存图像?

Java 是否在应用程序文件夹中保存图像?,java,android,image,gallery,Java,Android,Image,Gallery,我正在制作一个聊天应用程序,其中用户还可以选择发送图片。我想将这些图像保存到应用程序文件夹中,这样我就可以访问这些图像,用图片和文本填充聊天窗口中以前的消息。所以我的问题是如何将图像添加到应用程序文件夹? 谢谢首先,您必须将应用程序名称文件夹创建到sd卡中,然后您必须将文件/图像写入其中 String SDCardRoot = Environment.getExternalStorageDirectory().toString(); String filename = "fileName" +

我正在制作一个聊天应用程序,其中用户还可以选择发送图片。我想将这些图像保存到应用程序文件夹中,这样我就可以访问这些图像,用图片和文本填充聊天窗口中以前的消息。所以我的问题是如何将图像添加到应用程序文件夹?
谢谢

首先,您必须将应用程序名称文件夹创建到sd卡中,然后您必须将文件/图像写入其中

String SDCardRoot = Environment.getExternalStorageDirectory().toString();
String filename = "fileName" + ".jpg";
File myDir = new File(SDCardRoot + "/AppName");
myDir.mkdirs();
File file = new File(myDir, filename);
FileOutputStream fileOutput = new FileOutputStream(file);

//write the file into the sdcard folder specify your buffer , bufferLength 

fileOutput.write(buffer, 0, bufferLength);
fileOutput.close();
然后,只有您可以访问应用程序文件夹中的文件

       File imgFile;
       String path = Environment.getExternalStorageDirectory() + "/AppName/" + ".jpg";
        imgFile = new File(path);

        if (imgFile.exists()) {
            Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
            imageView.setImageBitmap(bitmap);
        }

我想你指的是软件包应用程序的可绘制文件夹。??我不确定你能做到。您必须使用应用缓存存储或内部/外部存储文件夹,您可以在其中创建和存储图像。非常感谢您的帮助!