zoukankan      html  css  js  c++  java
  • logcat

    1. String shell = "logcat";  
    2.                 try  
    3.                 {  
    4.                     Process process = Runtime.getRuntime().exec(shell);  
    5.                     InputStream inputStream = process.getInputStream();  
    6.                       
    7.                       
    8.                     boolean sdCardExist = Environment.getExternalStorageState().equals(  
    9.                             android.os.Environment.MEDIA_MOUNTED);  
    10.                     File dir = null;  
    11.                     if (sdCardExist)  
    12.                     {  
    13.                         dir = new File(Environment.getExternalStorageDirectory().toString()  
    14.                                 + File.separator + "logcatwyx.txt");  
    15.                         if (!dir.exists())  
    16.                         {  
    17.                             dir.createNewFile();  
    18.                         }  
    19.   
    20.                     }  
    21.                     byte[] buffer = new byte[1024];  
    22.                     int bytesLeft = 5 * 1024 * 1024// Or whatever  
    23.                     try  
    24.                     {  
    25.                         FileOutputStream fos = new FileOutputStream(dir);  
    26.                         try  
    27.                         {  
    28.                             while (bytesLeft > 0)  
    29.                             {  
    30.                                 int read = inputStream.read(buffer, 0, Math.min(bytesLeft,  
    31.                                         buffer.length));  
    32.                                 if (read == -1)  
    33.                                 {  
    34.                                     throw new EOFException("Unexpected end of data");  
    35.                                 }  
    36.                                 fos.write(buffer, 0, read);  
    37.                                 bytesLeft -= read;  
    38.                             }  
    39.                         } finally  
    40.                         {  
    41.                             fos.close(); // Or use Guava's  
    42.                                          // Closeables.closeQuietly,  
    43.                             // or try-with-resources in Java 7  
    44.                         }  
    45.                     } finally  
    46.                     {  
    47.                         inputStream.close();  
    48.                     }  
    49. //                    String logcat = convertStreamToString(inputStream);  
    50. //                    outputFile2SdTest(logcat, "logwyx.txt");  
    51.                     Log.v(TAG, "LOGCAT = ok" );  
    52.                 } catch (IOException e)  
    53.                 {  
    54.                     e.printStackTrace();  
    55.                 }  
  • 相关阅读:
    pandas模块篇(终章)及初识mataplotlib
    pandas模块篇(之三)
    pandas模块篇(之二)
    numpy最后一部分及pandas初识
    anaconda及jupyter notebook的使用之numpy模块的用法(2)
    anaconda及jupyter notebook的了解及使用方法(1)
    python初略复习(2)及python相关数据分析模块的介绍
    Python回顾笔记(此讲大致说明,详情请看之前的笔记)
    Python第三讲
    折半算法
  • 原文地址:https://www.cnblogs.com/fx2008/p/3131578.html
Copyright © 2011-2022 走看看