问题
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