【发布时间】:2016-10-28 07:10:19
【问题描述】:
public void saveByteArrayToFile(Context context){
Log.v(TAG, "Save byte array to file");
switch(mType){
case ChatMessage.AUDIO_MESSAGE:
filePath = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_MUSIC).getAbsolutePath()+"/"+fileName;
break;
case ChatMessage.VIDEO_MESSAGE:
filePath = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath()+"/"+fileName;
break;
case ChatMessage.FILE_MESSAGE:
filePath = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()+"/"+fileName;
break;
case ChatMessage.DRAWING_MESSAGE:
filePath = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath()+"/"+fileName;
break;
}
System.out.println("Mera path"+filePath);
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
try {
FileOutputStream fos=new FileOutputStream(file.getPath());
fos.write(byteArray);
fos.close();
Log.v(TAG, "Write byte array to file DONE !");
}
catch (java.io.IOException e) {
e.printStackTrace();
Log.e(TAG, "Write byte array to file FAILED !");
}
}
java.io.FileNotFoundException: /storage/sdcard0/Android/data/... 原因:android.system.ErrnoException: open failed: ENOENT (No such file or directory)
我在创建文件时收到此错误。
【问题讨论】:
-
也许您没有写入该路径的权限?
标签: java android filenotfoundexception fileoutputstream