Java-Runtime

Runtime应用之:在安全环境中,在多任务操作系统中使用Java去执行其他程序(比如在Java中调用cmd shell去执行一些命令)

通过adb shell pm clear + 包名,可以清除apk包的缓存信息,但是需要通过Java程序去实现,具体实现类如下:

 1 import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStreamReader;
 4
 5
 6 public class ExecCommand {
 7
 8     /**
 9      * @ 调用cmd命令
10      */
11     private String command = null;
12     //构造函数
13     public ExecCommand(String command){
14         this.command = command;
15     }
16
17     //调用cmd执行命令的函数
18     public void execCommand(String command) throws IOException{
19         Runtime runtime = Runtime.getRuntime();
20         Process p = runtime.exec(command);
21         StringBuffer stringBuffer = new StringBuffer();
22         try{
23             if(p.waitFor() != 0)
24             {
25                 System.err.println("exit value = " + p.exitValue());
26             }
27             BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
28             String line = null;
29             while((line = in.readLine()) != null){
30                 stringBuffer.append(line);
31             }
32             System.out.println(stringBuffer.toString());
33         }catch(Exception e){
34             System.err.println(e);
35         }finally{
36             try{
37                 p.destroy();
38             }catch(Exception e){
39             }
40         }
41
42     }
43
44     /**
45      * @param args
46      * @throws IOException
47      */
48     public static void main(String[] args) throws IOException {
49         // TODO Auto-generated method stub
50         String command = "adb shell pm clear xxx.xxx.xxx.xxx";
51         ExecCommand execCommand = new ExecCommand(command);
52         execCommand.execCommand(command);
53     }
54
55 }

其中xxx.xxx.xxx.xxx代表具体的包名,这个程序如果执行成功的话,就会清除缓存,然后在eclipse的Console界面提示Success

时间: 2024-11-02 14:09:33

Java-Runtime的相关文章

There is insufficient memory for the Java Runtime Environment to continue问题解决

在linux系统下长时间进行性能测试,连续几次发生服务器假死无法连接上的情况,无奈只能重启服务器.在测试路径下发现hs_err_pid17285.log文件,打开文件查看其主要内容如下: # There is insufficient memory for the Java Runtime Environment to continue.# Cannot create GC thread. Out of system resources.# Possible reasons:#   The sy

Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion' 解决方案

一.描述 今天我先安装了jdk8,后来由于其他软件不兼容,又重新安装了jdk7并修改了环境变量为jdk7的,结果在cmd中输入Java -version发现还是用的jdk8的,于是我就将jdk8卸载后重启了机器. 重启后机器再次输入jdk -version命令时出现以下错误提示: 二.解决方案 将C:\Windows\System32目录下的java.exe删除即可. Error: Registry key 'Software\JavaSoft\Java Runtime Environment'

经典错误重现->Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to

经常碰到这种错误,错误代码如下: Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run STS,No Java Virtual machine was found after searching the following locations:..............................................javaw.exe in y

Java Runtime.availableProcessors()方法

Java Runtime.availableProcessors()方法用法实例教程. 描述 java.lang.Runtime.availableProcessors() 方法返回到Java虚拟机的可用的处理器数量.此值可能会改变在一个特定的虚拟机调用.应用程序可用处理器的数量是敏感的,因此偶尔查询该属性,并适当地调整自己的资源使用情况. 声明 以下是声明java.lang.Runtime.availableProcessors()方法 public int availableProcesso

Java Runtime.getRuntime().exec 执行带空格命令解决办法

String command = OpenOffice_HOME + "program\\soffice -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard "; command = "cmd /c start "+command.replaceAll(" ","\" \""); P

A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/

linux系统下jdk是已经安装好的情况之下软件出现 A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/jre/bin/java java in yo

装完jdk运行java出现错误Error opening registry key 'Software\JavaSoft\Java Runtime Environment'

装完jdk运行java出现错误Error opening registry key 'Software\JavaSoft\Java Runtime Environment' 出现上述错误的终极解决办法是jdk安装路径里面不能含有中文...... 装完jdk运行java出现错误Error opening registry key 'Software\JavaSoft\Java Runtime Environment'

Ubuntu Eclipse启动时报错:A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No java virtual machine was found after searching the following locations:

此问题起于我在Ubuntu1004上装了两个版本的eclipse:Galieo+helios:卸载前者后出现启动不了eclipse的问题:在网上找了下,可以按如下过程进行解决: Eclipse 3.6 在 Ubuntu 10.04 下会出现一个很奇怪的现象,我没有经过测试,无法确定是Ubuntu 10.04 还是 JDK 还是 Eclipse本身造成的. 这个现象是: 可以在终端顺利启动Eclipse,但是鼠标双击,或者用起动器启动就会出现如下的内容: A Java RunTime Enviro

adt bundle启动eclipse出错:A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse.

在ubuntu12.04安装好jdk,然后设置好环境变量,然后继续安装好adt bundle 在终端进入adt bundle下的eclipse启动eclipse时没问题 但是从图形界面进入adt bundle下的eclipse启动eclipse时出错,提示如下: A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virt

eclipse 启动报错,A Java RunTime Environment (JRE) or Java Development Kit (JDK) must

A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No java virtual machine was found after searching the following locations:D:\Program   Files\eclipse\jre\bin\javaw.exe javaw.exe 加了环境变量也不行 错误就出在