Java Basics about Conversion flow

Source: Internet
Author: User

There are two types of conversion streams: InputStreamReader: Converting a byte stream to a character stream OutputStreamWriter: converting a character stream to a byte stream when is the conversion stream used? By the following analysis: Flow objects A lot, first of all to identify the flow object. Through three points to complete: 1, clear source and destination source: input stream. InputStream Reader purpose: output stream. OutputStream Writer2, whether the manipulated data is plain text. is: Character stream no: byte stream 3, when the system is clear, then clear which specific object to use. Differentiate by device: Source device: Memory, hard disk, keyboard purpose device: Memory, hard disk, console with an example simple description: The keyboard input data saved to a file, enter "Over" indicates the end of the entry. Detailed analysis: Source: Choose from InputStream Reader; Because it is keyboard input is plain text, so use reader. Equipment: keyboard, so with system.in; Found that system.in is the operation of the byte stream, and reader (character stream) contradiction, it is necessary to use the conversion stream InputStreamReader in order to improve operational efficiency, the use of buffer technology, choose BufferedReader Purpose: From OutputStream Writer Select because it is a text file, so choose Writer, device: Hard disk, a file, select FileWriter in order to improve operational efficiency, using buffer technology, choose Bufferedwriterimport Java.io.*;class Readinfile{public static void Main (string[] args) throws IOException//Here asked for convenience reading. Do not do exception handling {BufferedReader bufr=new BufferedReader (New InputStreamReader (system.in));//convert byte stream to character stream BufferedWriter bufw= New BufferedWriter (New FileWriter ("Readin.txt")); String Line=null;while ((Line=bufr.readline ())!=null) {if (' over '. Equals (line)] Break;bufw.write (line); bufw.newline ();} Bufw.close (); Bufr.close ();}}

Java basics about conversion flow

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.