`

java 不用jni 也可以获得当前系统信息

阅读更多

最近做个项目,就是要取得cpu占有率等等的系统信息,一开始以为要用动态链接库了,但后来发现可以像下面这样做,不去调用jni,这样省去了很多看新技术的时间o(∩_∩)o...

在Java中,可以获得总的物理内存、剩余的物理内存、已使用的物理内存等信息,下面例子可以取得这些信息,并且获得在Windows下的内存使用率。
     首先编写一个MonitorInfoBean类,用来装载监控的一些信息,包括物理内存、剩余的物理内存、已使用的物理内存、内存使用率等字段,该类的代码如下:

Java代码 复制代码
  1. package com.amgkaka.performance;   
  2.   
  3. /** *//**  
  4.  * 监视信息的JavaBean类.  
  5.  * @author  amg  
  6.  * @version 1.0   
  7.  * Creation date: 2008-4-25 - 上午10:37:00  
  8.  */  
  9. public class MonitorInfoBean {   
  10.     /** *//** 可使用内存. */  
  11.     private long totalMemory;   
  12.        
  13.     /** *//** 剩余内存. */  
  14.     private long freeMemory;   
  15.        
  16.     /** *//** 最大可使用内存. */  
  17.     private long maxMemory;   
  18.        
  19.     /** *//** 操作系统. */  
  20.     private String osName;   
  21.        
  22.     /** *//** 总的物理内存. */  
  23.     private long totalMemorySize;   
  24.        
  25.     /** *//** 剩余的物理内存. */  
  26.     private long freePhysicalMemorySize;   
  27.        
  28.     /** *//** 已使用的物理内存. */  
  29.     private long usedMemory;   
  30.        
  31.     /** *//** 线程总数. */  
  32.     private int totalThread;   
  33.        
  34.     /** *//** cpu使用率. */  
  35.     private double cpuRatio;   
  36.   
  37.     public long getFreeMemory() {   
  38.         return freeMemory;   
  39.     }   
  40.   
  41.     public void setFreeMemory(long freeMemory) {   
  42.         this.freeMemory = freeMemory;   
  43.     }   
  44.   
  45.     public long getFreePhysicalMemorySize() {   
  46.         return freePhysicalMemorySize;   
  47.     }   
  48.   
  49.     public void setFreePhysicalMemorySize(long freePhysicalMemorySize) {   
  50.         this.freePhysicalMemorySize = freePhysicalMemorySize;   
  51.     }   
  52.   
  53.     public long getMaxMemory() {   
  54.         return maxMemory;   
  55.     }   
  56.   
  57.     public void setMaxMemory(long maxMemory) {   
  58.         this.maxMemory = maxMemory;   
  59.     }   
  60.   
  61.     public String getOsName() {   
  62.         return osName;   
  63.     }   
  64.   
  65.     public void setOsName(String osName) {   
  66.         this.osName = osName;   
  67.     }   
  68.   
  69.     public long getTotalMemory() {   
  70.         return totalMemory;   
  71.     }   
  72.   
  73.     public void setTotalMemory(long totalMemory) {   
  74.         this.totalMemory = totalMemory;   
  75.     }   
  76.   
  77.     public long getTotalMemorySize() {   
  78.         return totalMemorySize;   
  79.     }   
  80.   
  81.     public void setTotalMemorySize(long totalMemorySize) {   
  82.         this.totalMemorySize = totalMemorySize;   
  83.     }   
  84.   
  85.     public int getTotalThread() {   
  86.         return totalThread;   
  87.     }   
  88.   
  89.     public void setTotalThread(int totalThread) {   
  90.         this.totalThread = totalThread;   
  91.     }   
  92.   
  93.     public long getUsedMemory() {   
  94.         return usedMemory;   
  95.     }   
  96.   
  97.     public void setUsedMemory(long usedMemory) {   
  98.         this.usedMemory = usedMemory;   
  99.     }   
  100.   
  101.     public double getCpuRatio() {   
  102.         return cpuRatio;   
  103.     }   
  104.   
  105.     public void setCpuRatio(double cpuRatio) {   
  106.         this.cpuRatio = cpuRatio;   
  107.     }   
  108. }  
package com.amgkaka.performance;

/** *//**
 * 监视信息的JavaBean类.
 * @author  amg
 * @version 1.0 
 * Creation date: 2008-4-25 - 上午10:37:00
 */
public class MonitorInfoBean {
    /** *//** 可使用内存. */
    private long totalMemory;
    
    /** *//** 剩余内存. */
    private long freeMemory;
    
    /** *//** 最大可使用内存. */
    private long maxMemory;
    
    /** *//** 操作系统. */
    private String osName;
    
    /** *//** 总的物理内存. */
    private long totalMemorySize;
    
    /** *//** 剩余的物理内存. */
    private long freePhysicalMemorySize;
    
    /** *//** 已使用的物理内存. */
    private long usedMemory;
    
    /** *//** 线程总数. */
    private int totalThread;
    
    /** *//** cpu使用率. */
    private double cpuRatio;

    public long getFreeMemory() {
        return freeMemory;
    }

    public void setFreeMemory(long freeMemory) {
        this.freeMemory = freeMemory;
    }

    public long getFreePhysicalMemorySize() {
        return freePhysicalMemorySize;
    }

    public void setFreePhysicalMemorySize(long freePhysicalMemorySize) {
        this.freePhysicalMemorySize = freePhysicalMemorySize;
    }

    public long getMaxMemory() {
        return maxMemory;
    }

    public void setMaxMemory(long maxMemory) {
        this.maxMemory = maxMemory;
    }

    public String getOsName() {
        return osName;
    }

    public void setOsName(String osName) {
        this.osName = osName;
    }

    public long getTotalMemory() {
        return totalMemory;
    }

    public void setTotalMemory(long totalMemory) {
        this.totalMemory = totalMemory;
    }

    public long getTotalMemorySize() {
        return totalMemorySize;
    }

    public void setTotalMemorySize(long totalMemorySize) {
        this.totalMemorySize = totalMemorySize;
    }

    public int getTotalThread() {
        return totalThread;
    }

    public void setTotalThread(int totalThread) {
        this.totalThread = totalThread;
    }

    public long getUsedMemory() {
        return usedMemory;
    }

    public void setUsedMemory(long usedMemory) {
        this.usedMemory = usedMemory;
    }

    public double getCpuRatio() {
        return cpuRatio;
    }

    public void setCpuRatio(double cpuRatio) {
        this.cpuRatio = cpuRatio;
    }
}

 

接着编写一个获得当前的监控信息的接口,该类的代码如下所示:

Java代码 复制代码
  1. package com.amgkaka.performance;   
  2.   
  3. /** *//**  
  4.  * 获取系统信息的业务逻辑类接口.  
  5.  * @author amg * @version 1.0   
  6.  * Creation date: 2008-3-11 - 上午10:06:06  
  7.  */  
  8. public interface IMonitorService {   
  9.     /** *//**  
  10.      * 获得当前的监控对象.  
  11.      * @return 返回构造好的监控对象  
  12.      * @throws Exception  
  13.      * @author amgkaka  
  14.      * Creation date: 2008-4-25 - 上午10:45:08  
  15.      */  
  16.     public MonitorInfoBean getMonitorInfoBean() throws Exception;   
  17.   
  18. }  
package com.amgkaka.performance;

/** *//**
 * 获取系统信息的业务逻辑类接口.
 * @author amg * @version 1.0 
 * Creation date: 2008-3-11 - 上午10:06:06
 */
public interface IMonitorService {
    /** *//**
     * 获得当前的监控对象.
     * @return 返回构造好的监控对象
     * @throws Exception
     * @author amgkaka
     * Creation date: 2008-4-25 - 上午10:45:08
     */
    public MonitorInfoBean getMonitorInfoBean() throws Exception;

}

  该类的实现类MonitorServiceImpl如下所示:

Java代码 复制代码
  1. package com.amgkaka.performance;   
  2.   
  3. import java.io.InputStreamReader;   
  4. import java.io.LineNumberReader;   
  5.   
  6. import sun.management.ManagementFactory;   
  7.   
  8. import com.sun.management.OperatingSystemMXBean;   
  9.   
  10. /** *//**  
  11.  * 获取系统信息的业务逻辑实现类.  
  12.  * @author amg * @version 1.0 Creation date: 2008-3-11 - 上午10:06:06  
  13.  */  
  14. public class MonitorServiceImpl implements IMonitorService {   
  15.     //可以设置长些,防止读到运行此次系统检查时的cpu占用率,就不准了   
  16.     private static final int CPUTIME = 5000;   
  17.   
  18.     private static final int PERCENT = 100;   
  19.   
  20.     private static final int FAULTLENGTH = 10;   
  21.   
  22.     /** *//**  
  23.      * 获得当前的监控对象.  
  24.      * @return 返回构造好的监控对象  
  25.      * @throws Exception  
  26.      * @author amg     * Creation date: 2008-4-25 - 上午10:45:08  
  27.      */  
  28.     public MonitorInfoBean getMonitorInfoBean() throws Exception {   
  29.         int kb = 1024;   
  30.            
  31.         // 可使用内存   
  32.         long totalMemory = Runtime.getRuntime().totalMemory() / kb;   
  33.         // 剩余内存   
  34.         long freeMemory = Runtime.getRuntime().freeMemory() / kb;   
  35.         // 最大可使用内存   
  36.         long maxMemory = Runtime.getRuntime().maxMemory() / kb;   
  37.   
  38.         OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory   
  39.                 .getOperatingSystemMXBean();   
  40.   
  41.         // 操作系统   
  42.         String osName = System.getProperty("os.name");   
  43.         // 总的物理内存   
  44.         long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;   
  45.         // 剩余的物理内存   
  46.         long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;   
  47.         // 已使用的物理内存   
  48.         long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb   
  49.                 .getFreePhysicalMemorySize())   
  50.                 / kb;   
  51.   
  52.         // 获得线程总数   
  53.         ThreadGroup parentThread;   
  54.         for (parentThread = Thread.currentThread().getThreadGroup(); parentThread   
  55.                 .getParent() != null; parentThread = parentThread.getParent())   
  56.             ;   
  57.         int totalThread = parentThread.activeCount();   
  58.   
  59.         double cpuRatio = 0;   
  60.         if (osName.toLowerCase().startsWith("windows")) {   
  61.             cpuRatio = this.getCpuRatioForWindows();   
  62.         }   
  63.            
  64.         // 构造返回对象   
  65.         MonitorInfoBean infoBean = new MonitorInfoBean();   
  66.         infoBean.setFreeMemory(freeMemory);   
  67.         infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);   
  68.         infoBean.setMaxMemory(maxMemory);   
  69.         infoBean.setOsName(osName);   
  70.         infoBean.setTotalMemory(totalMemory);   
  71.         infoBean.setTotalMemorySize(totalMemorySize);   
  72.         infoBean.setTotalThread(totalThread);   
  73.         infoBean.setUsedMemory(usedMemory);   
  74.         infoBean.setCpuRatio(cpuRatio);   
  75.         return infoBean;   
  76.     }   
  77.   
  78.     /** *//**  
  79.      * 获得CPU使用率.  
  80.      * @return 返回cpu使用率  
  81.      * @author amg     * Creation date: 2008-4-25 - 下午06:05:11  
  82.      */  
  83.     private double getCpuRatioForWindows() {   
  84.         try {   
  85.             String procCmd = System.getenv("windir")   
  86.                     + "\\system32\\wbem\\wmic.exe process get Caption,CommandLine,"  
  87.                     + "KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";   
  88.             // 取进程信息   
  89.             long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));   
  90.             Thread.sleep(CPUTIME);   
  91.             long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));   
  92.             if (c0 != null && c1 != null) {   
  93.                 long idletime = c1[0] - c0[0];   
  94.                 long busytime = c1[1] - c0[1];   
  95.                 return Double.valueOf(   
  96.                         PERCENT * (busytime) / (busytime + idletime))   
  97.                         .doubleValue();   
  98.             } else {   
  99.                 return 0.0;   
  100.             }   
  101.         } catch (Exception ex) {   
  102.             ex.printStackTrace();   
  103.             return 0.0;   
  104.         }   
  105.     }   
  106.   
  107.     /** *//**  
  108.      * 读取CPU信息.  
  109.      * @param proc  
  110.      * @return  
  111.      * @author amg     * Creation date: 2008-4-25 - 下午06:10:14  
  112.      */  
  113.     private long[] readCpu(final Process proc) {   
  114.         long[] retn = new long[2];   
  115.         try {   
  116.             proc.getOutputStream().close();   
  117.             InputStreamReader ir = new InputStreamReader(proc.getInputStream());   
  118.             LineNumberReader input = new LineNumberReader(ir);   
  119.             String line = input.readLine();   
  120.             if (line == null || line.length() < FAULTLENGTH) {   
  121.                 return null;   
  122.             }   
  123.             int capidx = line.indexOf("Caption");   
  124.             int cmdidx = line.indexOf("CommandLine");   
  125.             int rocidx = line.indexOf("ReadOperationCount");   
  126.             int umtidx = line.indexOf("UserModeTime");   
  127.             int kmtidx = line.indexOf("KernelModeTime");   
  128.             int wocidx = line.indexOf("WriteOperationCount");   
  129.             long idletime = 0;   
  130.             long kneltime = 0;   
  131.             long usertime = 0;   
  132.             while ((line = input.readLine()) != null) {   
  133.                 if (line.length() < wocidx) {   
  134.                     continue;   
  135.                 }   
  136.                 // 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount,   
  137.                 // ThreadCount,UserModeTime,WriteOperation   
  138.                 String caption = Bytes.substring(line, capidx, cmdidx - 1)   
  139.                         .trim();   
  140.                 String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();   
  141.                 if (cmd.indexOf("wmic.exe") >= 0) {   
  142.                     continue;   
  143.                 }   
  144.                 // log.info("line="+line);   
  145.                 if (caption.equals("System Idle Process")   
  146.                         || caption.equals("System")) {   
  147.                     idletime += Long.valueOf(   
  148.                             Bytes.substring(line, kmtidx, rocidx - 1).trim())   
  149.                             .longValue();   
  150.                     idletime += Long.valueOf(   
  151.                             Bytes.substring(line, umtidx, wocidx - 1).trim())   
  152.                             .longValue();   
  153.                     continue;   
  154.                 }   
  155.   
  156.                 kneltime += Long.valueOf(   
  157.                         Bytes.substring(line, kmtidx, rocidx - 1).trim())   
  158.                         .longValue();   
  159.                 usertime += Long.valueOf(   
  160.                         Bytes.substring(line, umtidx, wocidx - 1).trim())   
  161.                         .longValue();   
  162.             }   
  163.             retn[0] = idletime;   
  164.             retn[1] = kneltime + usertime;   
  165.             return retn;   
  166.         } catch (Exception ex) {   
  167.             ex.printStackTrace();   
  168.         } finally {   
  169.             try {   
  170.                 proc.getInputStream().close();   
  171.             } catch (Exception e) {   
  172.                 e.printStackTrace();   
  173.             }   
  174.         }   
  175.         return null;   
  176.     }   
  177.        
  178.     /** *//**  
  179.      * 测试方法.  
  180.      * @param args  
  181.      * @throws Exception  
  182.      * @author amg     * Creation date: 2008-4-30 - 下午04:47:29  
  183.      */  
  184.     public static void main(String[] args) throws Exception {   
  185.         IMonitorService service = new MonitorServiceImpl();   
  186.         MonitorInfoBean monitorInfo = service.getMonitorInfoBean();   
  187.         System.out.println("cpu占有率=" + monitorInfo.getCpuRatio());   
  188.            
  189.         System.out.println("可使用内存=" + monitorInfo.getTotalMemory());   
  190.         System.out.println("剩余内存=" + monitorInfo.getFreeMemory());   
  191.         System.out.println("最大可使用内存=" + monitorInfo.getMaxMemory());   
  192.            
  193.         System.out.println("操作系统=" + monitorInfo.getOsName());   
  194.         System.out.println("总的物理内存=" + monitorInfo.getTotalMemorySize() + "kb");   
  195.         System.out.println("剩余的物理内存=" + monitorInfo.getFreeMemory() + "kb");   
  196.         System.out.println("已使用的物理内存=" + monitorInfo.getUsedMemory() + "kb");   
  197.         System.out.println("线程总数=" + monitorInfo.getTotalThread() + "kb");   
  198.     }   
  199. }  
package com.amgkaka.performance;

import java.io.InputStreamReader;
import java.io.LineNumberReader;

import sun.management.ManagementFactory;

import com.sun.management.OperatingSystemMXBean;

/** *//**
 * 获取系统信息的业务逻辑实现类.
 * @author amg * @version 1.0 Creation date: 2008-3-11 - 上午10:06:06
 */
public class MonitorServiceImpl implements IMonitorService {
    //可以设置长些,防止读到运行此次系统检查时的cpu占用率,就不准了
    private static final int CPUTIME = 5000;

    private static final int PERCENT = 100;

    private static final int FAULTLENGTH = 10;

    /** *//**
     * 获得当前的监控对象.
     * @return 返回构造好的监控对象
     * @throws Exception
     * @author amg     * Creation date: 2008-4-25 - 上午10:45:08
     */
    public MonitorInfoBean getMonitorInfoBean() throws Exception {
        int kb = 1024;
        
        // 可使用内存
        long totalMemory = Runtime.getRuntime().totalMemory() / kb;
        // 剩余内存
        long freeMemory = Runtime.getRuntime().freeMemory() / kb;
        // 最大可使用内存
        long maxMemory = Runtime.getRuntime().maxMemory() / kb;

        OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
                .getOperatingSystemMXBean();

        // 操作系统
        String osName = System.getProperty("os.name");
        // 总的物理内存
        long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;
        // 剩余的物理内存
        long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;
        // 已使用的物理内存
        long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb
                .getFreePhysicalMemorySize())
                / kb;

        // 获得线程总数
        ThreadGroup parentThread;
        for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
                .getParent() != null; parentThread = parentThread.getParent())
            ;
        int totalThread = parentThread.activeCount();

        double cpuRatio = 0;
        if (osName.toLowerCase().startsWith("windows")) {
            cpuRatio = this.getCpuRatioForWindows();
        }
        
        // 构造返回对象
        MonitorInfoBean infoBean = new MonitorInfoBean();
        infoBean.setFreeMemory(freeMemory);
        infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);
        infoBean.setMaxMemory(maxMemory);
        infoBean.setOsName(osName);
        infoBean.setTotalMemory(totalMemory);
        infoBean.setTotalMemorySize(totalMemorySize);
        infoBean.setTotalThread(totalThread);
        infoBean.setUsedMemory(usedMemory);
        infoBean.setCpuRatio(cpuRatio);
        return infoBean;
    }

    /** *//**
     * 获得CPU使用率.
     * @return 返回cpu使用率
     * @author amg     * Creation date: 2008-4-25 - 下午06:05:11
     */
    private double getCpuRatioForWindows() {
        try {
            String procCmd = System.getenv("windir")
                    + "\\system32\\wbem\\wmic.exe process get Caption,CommandLine,"
                    + "KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";
            // 取进程信息
            long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));
            Thread.sleep(CPUTIME);
            long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));
            if (c0 != null && c1 != null) {
                long idletime = c1[0] - c0[0];
                long busytime = c1[1] - c0[1];
                return Double.valueOf(
                        PERCENT * (busytime) / (busytime + idletime))
                        .doubleValue();
            } else {
                return 0.0;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return 0.0;
        }
    }

    /** *//**
     * 读取CPU信息.
     * @param proc
     * @return
     * @author amg     * Creation date: 2008-4-25 - 下午06:10:14
     */
    private long[] readCpu(final Process proc) {
        long[] retn = new long[2];
        try {
            proc.getOutputStream().close();
            InputStreamReader ir = new InputStreamReader(proc.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String line = input.readLine();
            if (line == null || line.length() < FAULTLENGTH) {
                return null;
            }
            int capidx = line.indexOf("Caption");
            int cmdidx = line.indexOf("CommandLine");
            int rocidx = line.indexOf("ReadOperationCount");
            int umtidx = line.indexOf("UserModeTime");
            int kmtidx = line.indexOf("KernelModeTime");
            int wocidx = line.indexOf("WriteOperationCount");
            long idletime = 0;
            long kneltime = 0;
            long usertime = 0;
            while ((line = input.readLine()) != null) {
                if (line.length() < wocidx) {
                    continue;
                }
                // 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount,
                // ThreadCount,UserModeTime,WriteOperation
                String caption = Bytes.substring(line, capidx, cmdidx - 1)
                        .trim();
                String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();
                if (cmd.indexOf("wmic.exe") >= 0) {
                    continue;
                }
                // log.info("line="+line);
                if (caption.equals("System Idle Process")
                        || caption.equals("System")) {
                    idletime += Long.valueOf(
                            Bytes.substring(line, kmtidx, rocidx - 1).trim())
                            .longValue();
                    idletime += Long.valueOf(
                            Bytes.substring(line, umtidx, wocidx - 1).trim())
                            .longValue();
                    continue;
                }

                kneltime += Long.valueOf(
                        Bytes.substring(line, kmtidx, rocidx - 1).trim())
                        .longValue();
                usertime += Long.valueOf(
                        Bytes.substring(line, umtidx, wocidx - 1).trim())
                        .longValue();
            }
            retn[0] = idletime;
            retn[1] = kneltime + usertime;
            return retn;
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                proc.getInputStream().close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    
    /** *//**
     * 测试方法.
     * @param args
     * @throws Exception
     * @author amg     * Creation date: 2008-4-30 - 下午04:47:29
     */
    public static void main(String[] args) throws Exception {
        IMonitorService service = new MonitorServiceImpl();
        MonitorInfoBean monitorInfo = service.getMonitorInfoBean();
        System.out.println("cpu占有率=" + monitorInfo.getCpuRatio());
        
        System.out.println("可使用内存=" + monitorInfo.getTotalMemory());
        System.out.println("剩余内存=" + monitorInfo.getFreeMemory());
        System.out.println("最大可使用内存=" + monitorInfo.getMaxMemory());
        
        System.out.println("操作系统=" + monitorInfo.getOsName());
        System.out.println("总的物理内存=" + monitorInfo.getTotalMemorySize() + "kb");
        System.out.println("剩余的物理内存=" + monitorInfo.getFreeMemory() + "kb");
        System.out.println("已使用的物理内存=" + monitorInfo.getUsedMemory() + "kb");
        System.out.println("线程总数=" + monitorInfo.getTotalThread() + "kb");
    }
}

 

该实现类中需要用到一个自己编写byte的工具类,该类的代码如下所示:

Java代码 复制代码
  1. package com.amgkaka.performance;   
  2.   
  3. /** *//**  
  4.  * byte操作类.  
  5.  * @author amg * @version 1.0   
  6.  * Creation date: 2008-4-30 - 下午04:57:23  
  7.  */  
  8. public class Bytes {   
  9.     /** *//**  
  10.      * 由于String.subString对汉字处理存在问题(把一个汉字视为一个字节),因此在  
  11.      * 包含汉字的字符串时存在隐患,现调整如下:  
  12.      * @param src 要截取的字符串  
  13.      * @param start_idx 开始坐标(包括该坐标)  
  14.      * @param end_idx   截止坐标(包括该坐标)  
  15.      * @return  
  16.      */  
  17.     public static String substring(String src, int start_idx, int end_idx){   
  18.         byte[] b = src.g
    分享到:
    评论

相关推荐

    JAVA上百实例源码以及开源项目

     Java数据压缩与传输实例,可以学习一下实例化套按字、得到文件输入流、压缩输入流、文件输出流、实例化缓冲区、写入数据到文件、关闭输入流、关闭套接字关闭输出流、输出错误信息等Java编程小技巧。 Java数组倒置...

    JAVA上百实例源码以及开源项目源代码

     Java数据压缩与传输实例,可以学习一下实例化套按字、得到文件输入流、压缩输入流、文件输出流、实例化缓冲区、写入数据到文件、关闭输入流、关闭套接字关闭输出流、输出错误信息等Java编程小技巧。 Java数组倒置...

    java开源包4

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包11

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包6

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包9

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包101

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包5

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包8

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包10

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包3

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包1

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    【文献综述】基于JAVA的俄罗斯方块游戏设计与实现.pdf

    2.2 跨平台性 Java 语言的第二个特性就是跨平台性[4],也就是说使用 Java 语言编写的程序可以在编 2 译后不用经过任何更改,就能在任何硬件设备条件下运行。这个特性经常被称为"一次编 译,到处运行" 。执行 Java ...

    java开源包2

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    java开源包7

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    Java资源包01

    jared是一个用来操作Windows注册表的 Java 类库,你可以用来对注册表信息进行读写。 GIF动画制作工具 GiftedMotion GiftedMotion是一个很小的,免费而且易于使用图像互换格式动画是能够设计一个有趣的动画了一系列...

    人脸识别系统源码以及数据库.rar

    把dll或so文件拷贝到java.library.path所包含的路径下,注意区分X86和X64,和当前jdk版本一致。 初始化项目 创建数据库arcsoft_face_demo,执行脚本arcsoft_face_demo.sql 使用idea启动项目 修改配置文件src\main\...

    《Android系统源代码情景分析》

    14.4.3 系统当前激活的应用程序窗口获得键盘消息 14.4.4 InputDispatcher获得键盘事件处理完成通知 14.5 InputChannel的注销过程 14.5.1 销毁应用程序窗口 14.5.2 注销Client端InputChannel 14.5.3 注销...

    阿里巴巴开源的分布式文件系统 TFS.zip

    TFS尚未对最终用户提供传统文件系统API,需要通过TFSClient进行接口访问,现有JAVA、JNI、C、PHP的客户端 TFS的NameServer作为中心控制节点,监控所有数据节点的运行状况,负责读写调度的负载均衡,同时管理一级元...

Global site tag (gtag.js) - Google Analytics