我有dat文件,它是二进制file.It,目前在我的项目的原始文件夹中。我想在我的程序中使用这个文件。我希望将其复制到设备上的特定位置,但在执行该方法时,我将得到错误的“未能读取数据元数据”。
以下是一种方法:
public void copyRawOnSdCard(){
File sdcard = Environment.getExternalStorageDirectory();
String targetPath = sdcard.getAbsolutePath() + File.separator + "shape_predictor_68_face_landmarks.dat";
File file = new File(targetPath);
if (!file.exists())
{
final ProgressDialog pd; pd = ProgressDialog.show(this, "Copy Files for the First Time", "Please wait",
true);
pd.show();
InputStream in = getResources().openRawResource(
getResources().getIdentifier("shape_predictor_68_face_landmarks",
"raw", getPackageName()));
FileOutputStream out = null;
try {
out = new FileOutputStream(targetPath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try{
in.close();
}catch (IOException e) {
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
pd.cancel();
}
}想法?谢谢
发布于 2017-06-12 10:49:15
显然,还有另一种实现解决方案,即将其放在Asset文件夹中的.dat二进制文件中。
以下是实施情况:
https://stackoverflow.com/questions/4447477/how-to-copy-files-from-assets-folder-to-sdcard
对我来说很管用。
https://stackoverflow.com/questions/44496185
复制相似问题