Android 将文件从数据文件夹复制到emulator中数据的子文件夹

Android 将文件从数据文件夹复制到emulator中数据的子文件夹,android,Android,我想将图像文件从一个位置复制到另一个位置,我的图像文件存储在数据位置 android emulator中的文件夹,我想复制或移动数据文件夹子文件夹中的文件夹 为此,我使用了 文件、FileInputStream和FileOutputStream。现在我无法理解如何给出正确的路径 文件存储在android emulator中。请帮我解决这个问题。试试这个,仅用于图像 private File imageFile; private boolean writeFile() {

我想将图像文件从一个位置复制到另一个位置,我的图像文件存储在数据位置

android emulator中的文件夹,我想复制或移动数据文件夹子文件夹中的文件夹

为此,我使用了

文件、FileInputStream和FileOutputStream。现在我无法理解如何给出正确的路径


文件存储在android emulator中。请帮我解决这个问题。

试试这个,仅用于图像

    private File imageFile;

        private boolean writeFile() {
            imageFile = new File(
                    getApplicationContext().getFilesDir() + "/images/",
                    "sample.png");

           /* 
               Image save to  "/data/data/com.mycomp.android.test/files/images/sample.png"    
               com.mycomp.android.test  is your package name        
           */

            String savePath = imageFile.getAbsolutePath();
            System.out.println("savePath :" + savePath + ":");

            FileOutputStream fileOutputStream = null;
            try {
                fileOutputStream = new FileOutputStream(savePath, false);
            } catch (FileNotFoundException ex) {
                String parentName = new File(savePath).getParent();
                if (parentName != null) {
                    File parentDir = new File(parentName);
                    if ((!(parentDir.exists())) && (parentDir.mkdirs()))
                        try {
                            fileOutputStream = new FileOutputStream(savePath, false);
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }

                }
            }


          /* 
              path which image you need to move on data folder
           */


            String path = Environment.getExternalStorageDirectory()
                    + "/amit/amit.png";
            File imgFile = new File(path);

            Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

            byte[] imgBuffer = stream.toByteArray();

            boolean result = true;

            try {
                fileOutputStream.write(imgBuffer);
                fileOutputStream.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                result = false;
            } catch (IOException e2) {
                e2.printStackTrace();
                result = false;
            } finally {
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                        result = false;
                    }
                }
            }

            return result;

        }

您好,此邮政编码是否有效