zoukankan      html  css  js  c++  java
  • android Utils常用代码

    
    
    一、Log日志写入SD卡、命令执行方法

    二、String字符串十进制/十六进制相互转换




    =======================================================================================================================
    一、Log日志写入SD卡、命令执行方法
    1
    /* 2 * Log日志记录打印 3 */ 4 public static void write_sys_log(String strlog) { 5 try { 6 strlog = " " + strlog + " "; 7 String fileName="/sdcard/hlog.txt"; 8 9 File file = new File(fileName); 10 if( !file.exists()) { 11 file.createNewFile(); 12 } 13 FileWriter writer = new FileWriter(fileName, true); 14 writer.write(strlog); 15 writer.close(); 16 17 } catch(Exception e) { 18 } 19 } 20 21 /** 22 * 删除命令 23 */ 24 public static void commandExec(String cmd) { 25 26 try { 27 28 Runtime.getRuntime().exec(cmd); 29 30 } catch (IOException e) { 31 32 e.printStackTrace(); 33 } 34 }

     二、String字符串十进制/十六进制相互转换

     1 private static String hexString="0123456789ABCDEF";
     2 
     3 public static String strEncode10_16(String str10) {
     4         byte[] bytes=str10.getBytes(); 
     5         StringBuilder sb= new StringBuilder(bytes.length * 2);
     6         
     7         for(int i=0;i<bytes.length;i++) 
     8         { 
     9             sb.append(hexString.charAt((bytes[i]&0xf0)>>4)); 
    10             sb.append(hexString.charAt((bytes[i]&0x0f)>>0)); 
    11         } 
    12         return sb.toString();     
    13     }
    14 
    15 public String strDecode16_10(String str16) {
    16         
    17         ByteArrayOutputStream baos = new ByteArrayOutputStream(str16.length()/2);
    18         
    19         for(int i=0;i<str16.length();i+=2) 
    20             baos.write((hexString.indexOf(str16.charAt(i)) << 4 | hexString.indexOf(str16.charAt(i+1)))); 
    21             return new String(baos.toByteArray());     
    22     }
  • 相关阅读:
    如何使用C++构建一个极坐标系?
    归一化 [a] 到 [b] 区间
    ffmpeg 如何转换 rgb 图片到 yuv420p?如何使用 C 语言实现 rgb24 如何转换 yuv420p ?
    如何写一个通用的网络包?
    jenkins 配置参数为tag
    jmeter函数助手digest使用简介
    RD-T: 3540 Front Impact Bumper Model
    Listary软件的使用
    Adams各种材料的接触力参数
    Spring 使用构造方法注入方式
  • 原文地址:https://www.cnblogs.com/Miami/p/5421697.html
Copyright © 2011-2022 走看看