JAVA-I/O stream read Image byte code

Source: Internet
Author: User

Test class public class Test {public static void main (string[] args) {image img = new image (); String str = img.getrimg (); Img.getwimg (str); }//input stream import Java.io.BufferedInputStream; Import Java.io.BufferedOutputStream; Import Java.io.File; Import Java.io.FileInputStream; Import java.io.FileNotFoundException; Import Java.io.FileOutputStream; Import java.io.IOException; public class Image {public String getrimg () {StringBuilder builder = new StringBuilder (1000000); int i; try {new File ("t Ext//img.txt "). CreateNewFile (); FileInputStream in = new FileInputStream ("Text//img.txt"); Bufferedinputstream bis = new Bufferedinputstream (in); while ((I=in.read ())!=-1) {builder.append ((char) i);} bis.close (); }catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} finally{return builder.tostring ();} Output stream public void getwimg (String content) {try {new File ("Text//img.jpg"). CreateNewFile (); FileOutputStream out = new FileOutputStream ("Text//img.jpg"); Bufferedoutputstream BOS = new Bufferedoutputstream (out); char[] ch = content.tochararray (); SYSTEM.OUT.PRINTLN (CH); for (int i=0;i<ch.length;i++) {bos.write (ch[i]);} bos.flush (); Bos.close (); catch (IOException e) {e.printstacktrace ();}} }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.