“video/video_sample.mp4” 目录解释:asset文件下,有一个文件夹video,video文件夹中,放着一个video_sample.mp4视频文件,文件路径即:video/video_sample.mp4
String targetPath = Constants.getAudioTempPath();
path=FileUtils.copyAssetFile(mContext,"video/video_sample.mp4",targetPath);
public static String copyAssetFile(Context context, String fileName, String targetFilePath) {
InputStream is = null;
FileOutputStream os = null;
try {
is = context.getAssets().open(fileName);
if (!new File(targetFilePath).getParentFile().exists()) {
new File(targetFilePath).getParentFile().mkdirs();
}
os = new FileOutputStream(targetFilePath);
byte[] buffer = new byte[1024];
int len;
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
os.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
if (os != null)
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return targetFilePath;
}
手机根目录:String targetPath=”/sdcard/”;