Java验证码读取
来源:互联网 发布:化学分析软件 编辑:程序博客网 时间:2024/05/22 01:35
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class ImgDecode{
public static byte[] readInputStream(InputStream in) throws Exception{
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len=in.read(buffer)) != -1 ){
out.write(buffer, 0, len);
}
in.close();
return out.toByteArray();
}
public static void decodeImage(String imgpath){
String path = imgpath.substring(0,imgpath.lastIndexOf("\\"));
System.out.println("path="+path);
String cmd = "cmd /c start .\\decode.bat "+"\""+imgpath+"\"";
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
URL url = new URL("http://url/checkcode/picCheckCode");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
InputStream in = conn.getInputStream();
byte[] data = readInputStream(in);
File imageFile = new File("abc.png");
FileOutputStream out = new FileOutputStream(imageFile);
out.write(data);
out.close();
System.out.println("imgpath="+imageFile.getAbsolutePath());
decodeImage(imageFile.getAbsolutePath());
try{
Thread.sleep(1000);
}catch(Exception e){
e.printStackTrace();
}
InputStream in1 = new FileInputStream(new File(".\\1.txt"));
byte[] b = new byte[1024];
int len = -1;
while((len=in1.read(b))!=-1){
in1.read(b);
}
if(in!=null){
try{
in1.close();
}catch(Exception e){
e.printStackTrace();
}
}
String out1 = new String(b);
System.out.println(out1);
}
}
decode.bat:
@echo off
tesseract.exe %1 1 -1
)
exit
- Java验证码读取
- 读取图形验证码
- java验证码 验证
- C#语音读取验证码
- 手机自动读取验证码
- Android短信验证码读取
- php规则验证码读取
- Selenium/Java读取动态页面图片验证码,tesseract转换为文本
- Android自动读取短信验证码
- 读取短信自动填写验证码功能
- android自动读取短信验证码
- 实现短信验证码自动拦截读取
- Java入门开发POI读取导入Excel文件及验证
- JAVA 验证码
- java验证码类
- java随机验证码
- JAVA中文验证码
- java 实现验证码
- 黑马程序员——Java学习笔记——数组的排序和查找
- cassandra counter 类型使用注意事项
- 【leetcode】Implement Queue using Stacks
- Laravel资料总结
- 242-e-Valid Anagram
- Java验证码读取
- 高清屏的背景图片适配
- C++ 常见面试题目 (二)
- JQuery隐藏,显示div的方法
- [objective-c]获取ip地址
- C语言编程入门——指针(下)
- STM32 TFT学习笔记——SD卡读写
- 可滑动关闭的对话框(一)
- 华为是怎样研发的(12)——FMEA分析