An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified
. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.
charset
Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.
For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- Since:
- JDK1.1
- See Also:
BufferedReader
,InputStream
,Charset
java.io.BufferedReader
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in = new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.
- Since:
- JDK1.1
- See Also:
FileReader
,InputStreamReader
java.lang.StringBuilder
-
A mutable sequence of characters. This class provides an API compatible with
StringBuffer
, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement forStringBuffer
in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference toStringBuffer
as it will be faster under most implementations.The principal operations on a
StringBuilder
are theappend
andinsert
methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder. Theappend
method always adds these characters at the end of the builder; theinsert
method adds the characters at a specified point.For example, if
z
refers to a string builder object whose current contents are "start
", then the method callz.append("le")
would cause the string builder to contain "startle
", whereasz.insert(4, "le")
would alter the string builder to contain "starlet
".In general, if sb refers to an instance of a
StringBuilder
, thensb.append(x)
has the same effect assb.insert(sb.length(), x)
. Every string builder has a capacity. As long as the length of the character sequence contained in the string builder does not exceed the capacity, it is not necessary to allocate a new internal buffer. If the internal buffer overflows, it is automatically made larger.Instances of
StringBuilder
are not safe for use by multiple threads. If such synchronization is required then it is recommended thatStringBuffer
be used.- Since:
- 1.5
- See Also:
StringBuffer
,String
, Serialized Form
关于String类的split用法
-
s1="国|";
-
s2="中|国";
-
s1.split("\\|")返回的string数组只有一个元素,国
-
s2.split("\\|")返回的数组有两个元素,中 国
-
也就是java内封装的split函数有去掉空字符串的作用。
查看java 版本号 java -version