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 bytearrayinputstreamto used in showimage code:

imageio.read(imageinput); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -