今天在學(xué)習(xí)UncaughtExceptionHandler的時候,準備寫一個異常的日子阅畴,結(jié)果發(fā)現(xiàn)控制臺有java.io.IOException: open failed: EINVAL (Invalid argument)輸出,
而且原本要創(chuàng)建的文件也沒有創(chuàng)建成功担敌,看代碼找了半天沒有發(fā)現(xiàn)原因碧库,結(jié)果問度娘發(fā)現(xiàn)我的文件名中包含了:,發(fā)現(xiàn)是在android中咏删,創(chuàng)建文件時,我是用的是如下代碼
private void writeToSDcard(Throwable ex) throws IOException, PackageManager.NameNotFoundException {
//如果沒有SD卡盼产,直接返回
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
return;
}
File filedir = new File(PATH);
if (!filedir.exists()) {
filedir.mkdirs();
}
long currenttime = System.currentTimeMillis();
String time = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date(currenttime));
File exfile = new File(PATH +File.separator+FILE_NAME+time + FILE_NAME_SUFEIX);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(exfile)));
Log.e("錯誤日志文件路徑",""+exfile.getAbsolutePath());
pw.println(time);
PackageManager pm = mContext.getPackageManager();
PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_ACTIVITIES);
//當前版本號
pw.println("App Version:" + pi.versionName + "_" + pi.versionCode);
//當前系統(tǒng)
pw.println("OS version:" + Build.VERSION.RELEASE + "_" + Build.VERSION.SDK_INT);
//制造商
pw.println("Vendor:" + Build.MANUFACTURER);
//手機型號
pw.println("Model:" + Build.MODEL);
//CPU架構(gòu)
pw.println("CPU ABI:" + Build.CPU_ABI);
ex.printStackTrace(pw);
pw.close();
}