第一步:首先,下载adb1.0.32.zip,里面有如下图的内容:
第二步:解压缩,复制Adb.exe,和fastboot.exe到System32,注意AdbWinUsbApi.dll,AdbWinApi.dll这两个复制到System文件夹,不然打不开!
第三步:打开adb,必须使用cmd,不然闪退;使用cmd直接输入adb即可;如图
第四步:安装android手机驱动
第五步:编写java代码 操作Adb
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class t1 { public static void main(String[] args){try { Process process = Runtime.getRuntime().exec("adb shell"); //adb shell final BufferedWriter outputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); final BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream())); //这里一定要注意错误流的读取,不然很容易阻塞,得不到你想要的结果, final BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); new Thread(new Runnable() { String line; public void run() { System.out.println("listener started"); try { while((line=inputStream.readLine()) != null) { System.out.println(line); } } catch (IOException e) { //e.printStackTrace(); } } }).start(); new Thread(new Runnable() { final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public void run() { System.out.println("writer started"); String line; try { while ((line =br.readLine()) != null) { outputStream.write(line + "\r\n"); outputStream.flush(); } } catch (IOException e) { //e.printStackTrace(); } } }).start(); int i = process.waitFor(); System.out.println("i=" + i); } catch (Exception e) { e.printStackTrace(); } } }
运行结果:console
说明已经成功开始执行!
原文:http://www.cnblogs.com/jokerjason/p/5828702.html