1, mastering the role of BufferedReader class2, master the basic format of keyboard input.Buffer: Represents buffers, the previous stringbuffer, the contents of the buffer can be changed, can improve efficiency.If you want to receive data of any length and avoid garbled characters, you can use BufferedReader. Public class Bufferedreaderextends ReaderBecause the input data may appear in Chinese, it is done h
Package BufferedReader; Import Java.io.BufferedReader; Import Java.io.File; Import java.io.FileNotFoundException; Import Java.io.FileReader; Import java.io.IOException;
Read data from a file BufferedReader, character stream--"string public class Test {public static void main (string[] args) throws ioexception{ FileReader put = new FileReader ("D://a.txt");//node stream//do{//System.out.println (Put.read (
One.If the buffer is an array, as previously said, then writing bufr.read (BUF) cannot be understood. This sentence can only be seen as BUFR this buffer object, using the Read method, read the data into the BUF, not the buffer object BUFR read BUF array.The buffer object has its own concrete method, rather than inheriting the parent class's read-reading method of a single character, depending on the principle.The ReadLine method is more optimized than the method of the read single character, whi
Label: style blog HTTP color Io ar Java SP Div Import Java. Io .* ; Import Java. util. vendor; Public Class C { Public Static Void Main (string [] ARGs) Throws Ioexception {string x1, x2; Int Sum = 0 ; System. Out. Print ( "Bufferedreader Method \ ninput two number :" ); // The
The readLine Method for BufferedReader source code analysis, bufferedreader
The readLine method is a very common method in BufferedReader.
With this function, we can read data from a row in an input stream.
To distinguish rows, use "\ r", "\ n", or "\ r \ n". below is the source code of readLine in BufferedReader.
Deta
File, fileinputstream, filereader, inputstreamreader, bufferedreader...
References:
L Chapter 12 of core Java
L detailed description of how to operate text files using Java
Http://java.ccidnet.com/art/3737/20041108/523627_1.html
L what is filereader class? What is the difference with fileinputstream ???
Http://book.hackbase.com/ask2/ask107572.htmOrganize and comp
specify the encoding format;
BufferedReader class
BufferedReader is extended by the reader class to provide a universal buffer for text reading, and provides a very useful readline, reads a line of text, reads text from a character input stream, buffers individual characters, and provides efficient reading of characters, arrays, and rows.
The relationship between Ps:inputstream, InputStreamReader and Re
Implement the same interface as the target object bufferedreader
Define a variable to remember the target object
Define a constructor to receive enhanced objects
Overwrite the method to be enhanced
For methods that do not want to be enhanced, directly call the method of the target object.
Package CN. liuning. demo; import Java. io. bufferedreader; import
-generated catch block
E.printstacktrace ();
}
}
}
InputStreamReaderInputStreamReader sealed the InputStream inside,It reads one character at a time in a higher-level way,The following example assumes that there is a document encoded as UTF8,It has only one Chinese character, "Chan".[Java]View PlainCopy
Import java.io.*;
Public class Main {
public static void Main (string[] args) throws FileNotFoundException, unsupportedencodingexc
on the execution environment's current OS to determine the output type of newline characterBufwriter.newline (); } bufreader.close (); Bufwriter.close (); } Catch(arrayindexoutofboundsexception e) {System.out.println ("No Files specified"); } Catch(IOException e) {e.printstacktrace (); } } } Operation Result:D:\hxy>java Ysu.hxy.BufferedReaderWriterDemo Test2.txtFsdafjads;faFasdfas
; try {fr=new FileReader ("E:\\javawenjian\\ioliou8.java"); Bfr=new BufferedReader (FR); String S=null; while ((S=bfr.readline ())!=null)/* ReadLine () a line of reads, without any line terminator, returns null if no data is read. But do not return carriage returns, so the output to print or write when you re
/* Bufferedreader improves performance by buffering input. It has two constructor functions: bufferedreader (Reader inputstream) bufferedreader (Reader inputstream, int bufsize). The first method is to create a buffer stream with the default buffer length. Second, the buffer length is input by bufsize. Similar to throttling, buffering an input primary stream also
Address: http://blog.csdn.net/moxie008/article/details/5663488
Http://blog.csdn.net/xiaoya629/article/details/5610670
Http://blog.csdn.net/hippoppower/article/details/4547876
. Inputstream, outputstream
Abstract class for processing byte streams
Inputstream is the superclass of all classes of the byte input stream. We generally use its subclass, such as fileinputstream.
Outputstream is the superclass of all classes of the byte output stream. We generally use its subclass, such as fileoutputstrea
improving good code habits. For example, remember to close the stream and network connection. Before reading the network stream, you can test whether the stream is ready.
Call the readline () method in bufferedreader
If (file. canRead () to if (bread. ready () TryUse of the readLine () method in Java iobufferedreader class
Because the readLine () method may throw an IOException, you need to add or not hand
I meanBufferedreaderObject,UseFilereaderAnd stringreader.When executing the Readline () of bufferedreader,Different results are also generated.As a result, I think that when executing Readline (), Java still usesThe memory space pointed to by the object pointer to execute read (),In this case, the O1 generated by O1 = new bufferedreader (New filereader (...) is e
Enter an integer and a real number on the keyboard, and sum the values.
The Code is as follows:
// Import Java. io. bufferedreader; import Java. io. *; public class inandout {/*** @ Param ARGs */public static void main (string [] ARGs) {int I = 0; float f = 0; string STR; try {bufferedreader BR = new
Today, we encountered a bug: There is an inputstream A, which contains 10 bytes of data to read, and two bufferedreader B1 and B2 Packages.
First, the read method of B1 is called and executed normally. Call the read method of B2 to find that the data cannot be read. After thinking for a long time, I came up with a conjecture that B1 had read all the data in a into its own buffer, so when B2 was reading it again, there was no data in.
So I wrote the
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.