How to move a file from sdcard to app data folder?

和自甴很熟 提交于 2019-12-11 12:46:44

问题


In my app I need to move files from the sdcard to /data/data/com.pack.main/ folder.The code I am using is this:

            ContextWrapper cw = new ContextWrapper(getApplicationContext());
            File directory = cw.getDir("/data/data/com.cuelearn.main/", Context.MODE_PRIVATE);
            File mypath=new File(directory,object.VIDEO_FILENAME+".mp4");
            copyFile(new File(Environment.getExternalStorageDirectory(),"/cue_learn_data/video_files/"+object.VIDEO_FILENAME+".mp4"),mypath);

and the copyFile() method is:

                public static void copyFile(File src, File dst) throws IOException
            {
                System.out.println("copying files");
                FileChannel inChannel = new FileInputStream(src).getChannel();
                FileChannel outChannel = new FileOutputStream(dst).getChannel();

                try
                {
                    inChannel.transferTo(0, inChannel.size(), outChannel);
                }
                finally
                {
                    if (inChannel != null)
                        inChannel.close();
                    if (outChannel != null)
                        outChannel.close();
                }
            }

Can any one tell me where I am going wrong. The file in the sdcard is present but still not working.May be anyone could give me a easier way to do this?

来源:https://stackoverflow.com/questions/9463686/how-to-move-a-file-from-sdcard-to-app-data-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!