package studyjava; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import org.omg.SendingContext.RunTime; public class install { public static void main(String[] args) throws Exception { String dir="D:\downapp\"; File f1=new File(dir); String[] apkname=f1.list(); for(int i=0;i<apkname.length;i++) { if(installapp(dir+apkname[i])) System.out.println(apkname[i]+"安装成功"); else System.out.println(apkname[i]+"没安装成功,或已经安装"); } } public static boolean installapp(String path) throws IOException, Exception { String[] b=new String[1024]; Process p=Runtime.getRuntime().exec("adb install "+path); Thread.sleep(4000); InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); String str; int i=0; while((str=br.readLine())!=null) { if(str.indexOf("Success")!=-1) i=1; } if(i==1) return true; else return false; } }