Using the byte stream class to read a binary file in Java

Source: Internet
Author: User

Package Cn.jbit.copy;import Java.io.bufferedinputstream;import Java.io.dataoutputstream;import java.io.File;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;import Java.io.inputstream;public class Test {/** * @param args */public static void main (string[] Arg s) {///1), create a file object with a filename of "c:\\01.jpg";//2, use a byte stream object to read into memory try {inputstream Filein = new FileInputStream (file);// DataInputStream in = new DataInputStream (Filein);//Use buffers to read objects more efficiently bufferedinputstream in = new Bufferedinputstream ( Filein); FileOutputStream fileout = new FileOutputStream ("D:\\3.jpg");D ataoutputstream dataout = new DataOutputStream (fileOut) ;//Use buffers to write objects more efficiently//bufferedoutputstream dataout=new Bufferedoutputstream (fileout); int temp;while (temp = In.read ())! =-1) {dataout.write (temp);}} catch (FileNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Au To-generated Catch blocke.printsTacktrace ();}}} 

  

Using the byte stream class to read a binary file in Java

Related Article

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.