The byte stream copies an image and the byte stream copies the image.

Source: Internet
Author: User

The byte stream copies an image and the byte stream copies the image.

1. Use Word throttling to read objects and associate images

2. Write stream objects with word throttling and create an image file.

3. Data Storage is completed through cyclic read/write.

4. Disable Resources

 

Instance code:

import java.io.*;class CopyPic {    public static void main(String[] args)     {        FileOutputStream fos = null;        FileInputStream fis = null;        try        {            fos = new FileOutputStream("c:\\2.jpg");            fis = new FileInputStream("c:\\1.jpg");            byte[] buf  = new byte[1024];            int len = 0;            while((len = fis.read(buf)) != -1){                fos.write(buf, 0 , len);            }        }        catch (IOException e)        {            throw new RuntimeException("failed!");        }        finally{            try            {                if(fis !=null)                    fis.close();            }            catch (IOException e)            {                throw new RuntimeException("read failed!");            }            try            {                if(fos !=null)                    fos.close();            }            catch (IOException e)            {                throw new RuntimeException("write failed!");            }        }    }}

How Can I copy multiple images in one file?

When you select an image, press Ctrl and select any image you want to select. This is "selected". copy and paste the image.

Finding a basic book on computers can help you learn basic operations easily.

In java, how to use throttling to display the content of a text, and then copy the content to another text

Haha ~~
I also want to join in ~~
Give it to me!

Import java. io. InputStream;
Import java. io. FileInputStream;
Import java. io. OutputStream;
Import java. io. FileOutputStream;

Class Copy {
Public static void main (String args []) {
Try {
InputStream FCM = new FileInputStream ("D:/file1.txt ");
Int size = FCM. available ();
Char [] ch = new char [size];
For (int I = 0; I <size; I ++ ){
Ch [I] = (char) FCM. read ();
}
String str = new String (ch );
System. out. println ("file1.txt file content \ n" + str );

OutputStream fos = new FileOutputStream ("D:/file2.txt ");
Byte [] words = str. getBytes ();
Fos. write (words, 0, words. length );
System. out. println ("\ n file1.txt file has been copied! ");
Fos. close ();
FCM. close ();
}
Catch (IOException ex ){
System. out. println ("the program has an error! ");
}
}
}
Reference: TS117 _ na

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.