java - How to do this without using Files? -
i have following code :
connection.response captcharesponse = jsoup.connect(captcha_url) .timeout(3000) .cookies(cookies) .useragent("mozilla/5.0") .method(method.get) .ignorecontenttype(true) .execute(); cookies.putall(captcharesponse.cookies()); // writing captcha image file fileoutputstream filewriter = new fileoutputstream(new file(captcha_filename)); filewriter.write(captcharesponse.bodyasbytes()); filewriter.close(); showimage(captcha_filename,"captcha");
showimage
function:
public void showimage(string filename,string title) throws ioexception { imageicon icon = new imageicon(imageio.read(new file(filename))); jframe frame = new jframe(title); jlabel imagelabel = new jlabel(); imagelabel.seticon(icon); frame.add(imagelabel); frame.setsize(100,100); frame.setlocationrelativeto(null); frame.setdefaultcloseoperation(jframe.dispose_on_close); frame.setvisible(true); }
i have captcha needs displayed. storing captcha in file , reading file each time. there way in can without involving files ?
you can use bytearrayoutputstream
instead of fileoutputstream
store captcha. then:
bytearrayinputstream imageinput=new bytearrayinputstream(outputstream.tobytearray());
to transform bytearrayoutputstream
bytearrayinputstream
to used in showimage
code:
imageio.read(imageinput);
Comments
Post a Comment