zoukankan      html  css  js  c++  java
  • 保存android程序崩溃日志到SD卡


    	private boolean writeToSDCard(Throwable ex) 
    	{
    		boolean isDealing = false;
    		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
    		{
    			RandomAccessFile randomAccessFile = null;
    			try
    			{
    				String fileName = SDCARDROOT + File.separator + "logs" + File.separator + "crash" + File.separator;
    				File file = new File(fileName);
    				if(!file.exists())
    					file.mkdirs();
    				randomAccessFile = new RandomAccessFile(fileName + paserTime(System.currentTimeMillis())+ ".log", "rw");
    				long fileLength = randomAccessFile.length();
    				randomAccessFile.seek(fileLength);
    				randomAccessFile.writeBytes(getThrowableInfo(ex));
    			} 
    			catch (IOException e) 
    			{
    				e.printStackTrace();
    			} 
    			finally 
    			{
    				if (randomAccessFile != null)
    				{
    					try 
    					{
    						randomAccessFile.close();
    						isDealing = true;
    					} 
    					catch (IOException e)
    					{
    						e.printStackTrace();
    					}
    				}
    			}
    		}
    		return isDealing;
    	}

    	private static String getThrowableInfo(Throwable ex)
    	{
    		StringWriter stringWriter = new StringWriter();
    		PrintWriter printWriter = new PrintWriter(stringWriter);
    		ex.printStackTrace(printWriter);
    		return stringWriter.toString();
    	}


  • 相关阅读:
    Spring Cloud概述
    Servlet调用流程和Spring MVC调用流程
    待看文章链接
    MyBatis之 resultMap 元素子元素详解
    MyBatis核心配置文件模板代码
    ios上架
    iOS打包部署
    Android XML绘图(4)——Bitmap
    Android XML绘图(2)——Layer
    Android XML绘图(3)——Selector
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5199349.html
Copyright © 2011-2022 走看看