Io (input and output) operations in java (IV), iooutputThe main operations of java io have been completed.This section describes other content about java io.Serializable serialization Instance 1: Object serialization Copy codeThe Code is as follows:Import
appropriate threads for subsequent processing. This approach is feasible when accessing streams, reader, and writer in an orderly manner. Note that the code that passes the stream data between threads should be synchronous.Note: In Java NIO, you can have a thread read and write to multiple "channel". For example, you have a lot of internet connections on, but only a small amount of data per connection, like a chat server, allows a thread to monitor m
{...Private void flushbuffer () throws ioexception {If (count> 0 ){Out. Write (BUF, 0, count );Count = 0;}}Public synchronized void write (int B) throws ioexception {If (count> = Buf. Length ){Flushbuffer ();}Buf [count ++] = (byte) B;}...}
This class provides a caching mechanism to write data into the output stream when the cache capacity reaches a certain number of bytes. First, it inherits filteroutpu
[Java iO] _ file class notes
Objectives of this chapter:
Measure the test taker's knowledge about the functions of the file class.You can use methods in the file class to operate files.
File class
In the entire Io package, the only class that indicates the file is the file class. You can use the File class to create and delete files. To use the File class, first
automatically create a path that does not exist. If the path does not exist, the file does not exist, and cannot be created, but the file does not exist but cannot be opened, a FileNotFoundException exception will be thrown. FileOutputStream (String name, boolean append) throws FileNotFoundExceptionFileOutputStream (File file, boolean append) throws FileNotFoundExceptionFileInputStream and FileOutputStream support all read/write methods provided by InputStream and OutputStream. Note: when insta
can be divided into which two, respectively, to illustrate1 "input and output relative to program2 "input stream InputStream3 "Output stream OutputStream===============================================================4. According to the implementation of the function is divided into which two, respectively, illustrate1 in accordance with the implementation of the function is divided into "node flow" "Processing flow"2 "node stream: OutputStream3 "Processing flow: OutputStreamWriter==============
Java learning notes 43 (brief introduction to the print stream and IO stream tools) and learning notes
Print stream:
There are two classes: PrintStream and PrintWriter. The methods of the two classes are the same. The difference is that the constructor
PrintStream: constructor: receives the File type, receives the string File name, and receives the byte output stream (OutputStream)
PringWriter: constructor:
1. Store the data in the collection into a text file case:Requirement: To store string data in the ArrayList collection into a text file?(1) Analysis:Through the meaning of the topic, we can know some of the following things,A string is stored in the ArrayList collection.Traverse the ArrayList collection to get the data.It is then stored in a text file.The text file description uses a character stream .(2)Data Source :ArraylistDestination :A.txt--FileWriter--BufferedWriter2. code example:1 Pack
public int skipbytes (int n) throws IOException
The file pointer moves backwards n bytes, and n is negative when the pointer does not move
public int read (byte[] b) throws IOException
Reads a maximum of b.length bytes into the array b
public void Write (byte[] b) throws IOException
Writes B.le
By reading the Java Io source code, you can find the basic architecture of Io. Note: This article is purely intended to record and share what you have learned. Some images and code are from other blogs. Sorry, I hope that people who have read this blog can leave your comments and give them a learning opportunity. Thank you very much !!!
* Byte-based
JAVA 47th-IO stream (1): file read/write
Input stream and output stream relative to memory
Read data from external devices to memory: Input
Write data in memory to external devices: Output
I/O streams often use base classes
Abstract base class of byte stream: InputStream, OutputStream
Abstract base class of characters: Reader and Writer
PS: The child classes generated by these four schools are suffixed with
cannot be saved during serialization, the value obtained by static object variables in deserialization is the value of the static variable corresponding to the corresponding class in the current jvm, and transient (transient) keyword is generally used to identify state variables that do not need to be passed during serialization.
Simple test code:
01Import java. io. FileInputStream;02Import
and provide methods such as print ().In addition, PrintWriter and PrintStream are directly created if no file object exists.They will overwrite the original files, but there is no way to add them.It's easy to solve this problem. Check the API documentation again. PrintWriter has a constructor PrintWriter (Writer out), that is, it can pass in the Writer object.PrintStream has a constructor PrintStream (OutputStream out), that is, it can pass in the OutputStream object.Therefore, we can write it
asynchronoussocketchannel created through asynchronoussocketchannel belongs to the same group and shares resources.
The callback interface of the asynchronous Io operation result of Java. NiO. channels. completionhandler is used to define the callback work after the IO operation is completed. The aio api allows two methods to process asynchronous operation resu
Next: "Architecture design: Inter-system Communication (4)--io communication model and Java Practice Medium", we continue to explain asynchronous IO7. Asynchronous IOIn the previous two articles, we explained the three IO models for blocking synchronous IO, non-blocking synchronous
) {
e.printstacktrace ();
} finally {
fis.close ();}}}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21-22Note: The above program finally uses the Fis.close () to turn off the input stream of the file, like JDBC programming, open the file IO resources in the program does not belong to the memory resources, garbage collection mechanism can not reclaim the resource, so should be shown to close the open
Reproduced from: http://blog.csdn.net/daijialin/article/details/231384Prior to JDK 1.4, Java IO Operations were concentrated in the Java.io package and were based on the streaming blocking (blocking) API. For most applications, such APIs are easy to use, however, some applications with high performance requirements, especially server applications, often require a more efficient way to process
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.