1.截图并保存到本地
package scriptall; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.plaf.SliderUI; public class screenshot { public static void getpictrue(String str1) throws IOException { Runtime r=Runtime.getRuntime(); r.exec("cmd /c adb shell screencap -p /sdcard/"+str1+".png"); } public static String picnametime() { Date date=new Date(); DateFormat format=new SimpleDateFormat("yy/MM/dd HH:mm:ss"); String time=format.format(date); String time2=filt(time); return time2; } public static String filt(String str) { Pattern p=Pattern.compile("[`~!@#$%^&*()+=|{}‘:;‘,//[//].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]"); Matcher m=p.matcher(str); return m.replaceAll("").replace(" ", "").trim(); } public static void main(String[] args) throws Exception { String picname; picname=picnametime(); getpictrue(picname); } }
解析:1)调用系统命令时一定要加cmd/c
r.exec("cmd /c adb shell screencap -p /sdcard/"+str1+".png");
2)获取系统时间
Date date=new Date();
DateFormat format=new SimpleDateFormat("yy/MM/dd HH:mm:ss");
String time=format.format(date);
3)过滤字符串
Pattern p=Pattern.compile("[`~!@#$%^&*()+=|{}‘:;‘,//[//].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]");
Matcher m=p.matcher(str);
return m.replaceAll("").replace(" ", "").trim();
原文:http://www.cnblogs.com/penghong2014/p/4973770.html