Original address: http://tutorials.jenkov.com/java-nio/nio-vs-io.htmlauthor : Jakob Jenkov translator : Guo proofreading: Fang FeiAfter learning the APIs for Java NIO and Io, a problem immediately poured into my mind:When should I use IO and when do I use NIO? In this article, I'll try to clearly parse the differences
JAVA learning lesson 49th-IO stream (III): Buffer Zone 2 amp; Decoration Design Mode
I. Simulate BufferedReader
Custom MyBuffereaReader
In the buffer zone, an array is encapsulated to provide external methods for Array Operations. These methods ultimately operate on the array badge.
Principle: extract data from the source and store it in the buffer zone. After the data is obtained, the system continues to
Transferred from: http://blog.csdn.net/keda8997110/article/details/19549493After learning the APIs for Java NIO and Io, a problem immediately poured into my mind:When should I use IO and when do I use NIO? In this article, I'll try to clearly parse the differences between Java NiO and
First, the concept
NiO is the new IO, the library is introduced in JDK1.4. NiO and IO have the same effect and purpose, but the implementation is different, NIO is mainly used in blocks, so the efficiency of NIO is much higher than IO. Two sets of NIO are provided in the Java API, one for standard input output NIO and
use the input character stream inputstreamreader instead of FileReader; he can specify character encoding.* 2. How to efficiently traverse the entire text file* You can use the buffered stream BufferedReader stream to read one line at a time.* @author User**/public class FileOprate2 {public static void Main (string[] args) {File F=new file ("D:\\liu.txt");File F1=new file ("D:\\liu1.txt");Char[] Chs=new char[1024];try {InputStreamReader insr=new InputStreamReader (new FileInputStream (f), "utf-
record the association between the sequence number and the new object. gets the object reference associated with the sequence number when it encounters the same as the object with the previously saved sequence number x. Some data cannot be serialized, so they are marked as transient, and static is not serializable. a serializable class can add validation or other behavior to the default read-write behavior. private void ReadObject (Ojbectinputstream in) throws
serializing and deserializing streamsThe flow of operations used to read an object from a stream ObjectInputStream called a deserialization streamThe flow of operations used to write objects to the stream ObjectOutputStream is called a serialized stream (the object is saved to a file)L Features: For manipulating objects . You can write an object to a file, or you can read an object from a file.object Serialization Stream ObjectOutputStreamObjectOutputStream writes the basic data type and graphic
2017-11-05 17:48:17IO streams in Java are categorized into two types, one is byte stream and the other is character stream. The character stream appears to simplify the read and write operations of text data. If the file you are manipulating is a text file, using a character stream can greatly simplify the operation, but if you do not know anything, use a byte stream.
BYTE stream
The two abstract base classes for a byte stream are:inputs
() throws ioexception{}Closes this file input stream and frees all system resources related to this stream. Throws a IOException exception.
2
protected void Finalize () throws IOException {}This method clears the connection to the file. Make sure that the Close method is called when the file input stream is no longer referenced. Throws a
? FalseUsing Shutdownoutput to close the output stream, is the socket closed? FalseClose the output stream using close, does the socket close? TrueCan the output stream be re-opened after using Shutdownoutputstream? ***Is the data in the output buffer discarded or sent? ****---------------------------------Server------------------------------I am the server, I am listening on the 9999 port ....I am the server, I am listening on the 9999 port ....Java.io.EOFExceptionAt Java.io.DataInputStream.rea
ArticleDirectory
Pipeline stream (thread communication Stream)
Pipeline stream (thread communication Stream)
The main function of a pipeline stream is to communicate between two threads, namely, pipedoutputstream and pipedinputstream ),If you want to output a pipe, you must put the output on the input stream.In the pipedoutputstream class, you can use the following method to connect to the MPs queue:
Public void connect (pipedinputstream SNK) throws
Java Programming IO operation is essential, long time not to play Io, review, write a few small programs, record, easy to access and learn.1. Give an array of integers, write them to a file, read them from the file, and print in reverse order of integer size. Packagecom.io.test;ImportJava.io.BufferedReader;ImportJava.io.File;ImportJava.io.FileInputStream;ImportJa
running the command "FS" to read "is always-1. So in the second while statement, the system jumps out when the first read is executed by the system. Why? -1 is returned for the result of the command. read. So C is not assigned at all, and even if it is assigned a value, C can only hold the next char.As for this solution, the idea is as follows: You read data to an int type variable date in one byte and one byte through the fins. Since date can be printed, it can be assigned to char c, naturally
character (or character set). The resulting bytes are accumulated in the buffer before writing to the underlying output stream. You can specify the size of this buffer, but the default buffer is large enough for most purposes. Note that the characters passed to the write () method are not buffered. For maximum efficiency, consider wrapping the outputstreamwriter into BufferedWriter to avoid frequent calls to the converter.* * Construction method* * Common methodsThe length of the lenth is writt
class diagram, writing to a network is actually writing files, but there is another step to process writing to the network, that is, the underlying operating system transfers data to other places rather than local disks ). Let's take a look at the InputStream abstract class code in jdk: [java] package java. io; public abstract class InputStream implements Closea
one, processing flow:Enhanced functionality that provides performance on top of node streams.the relationship between node flow and processing flowThe node stream (byte stream, character stream) is in the front line of IO operation, and all operations must be done through them;processing streams can handle other flows (increasing efficiency or operational flexibility).third, buffer flow1, byte buffer streamBufferedInputStreamBufferedOutputStream Packa
understand the role and usage of the pipeline, then look at the source code, it may be easier to understand.
In addition, PipedOutputStream's parent class OutputStream has been introduced in the Bytearrayoutputstream of Java IO series 03, source analysis and examples (including outputstream). Here is no longer the introduction of OutputStream.
PipedInputStream's parent class InputStream has been introduced
the read/write location to 0, and compact method without changing the read/write limit, copy the data from the current read/write location to the beginning of the internal bucket, and then move the read/write location to the next location of the copied data, the read/write limit is set to the capacity. The implementation of ByteBuffer can be divided into direct buffer and non-direct buffer. The direct buffer is directly completed using the underlying IO
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.