最近做个小的DEMO,录音时保存文件。但是老是在录的时候报FileNotFindException的错误。上网查说是没有找到文件名的错误,但是没有解决方法。
我的原始程序(部分)是
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMddHHmmss");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
mFileName=Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator +"pingantemp"+File.separator+"record"+File.separator+str+ ".amr";
oundFile = new File(mFileName);
目的是在录音时将当前时间作为文件名存在sd卡temp文件夹的record文件夹下。
后来发现文件输出和文件夹新建是两码事。这是程序第一次运行的。所以根本不存在temp/record文件夹。所以要判断是否存在这个文件夹,前面加上代码
File file=new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator +"temp"+File.separator+"record");
if (!file.exists()) {
file.mkdirs();
}