1. Keyboard entry--java with specific object encapsulation these input
Defining the In-inputstream type and Out-printstream type member variables in the system class
Blocking is method: Read () No data is blocked
Windows inside enter key for two bytes of \r-13\n-10
There is only one flow object from the system, so don't turn off the flow
InputStream in = system.in (called system stream, defined as type in Java)
Do not shut down because the system's stream is off or it will not work.
Stingbulider/stringbuffer empty with Delete ()
The end of the keyboard entry is usually the end of the custom
2. Conversion stream (conversion between byte stream and character stream)
The byte stream wants to take advantage of the character Buffer stream ReadLine ()--first converted to a character stream, decorated in a buffered stream
InputStreamReader and Outputstreamreader inherit reader
InputStreamReader (InputStream in)--byte flow to a character stream you can specify CharSet encoding
For the difference between byte and character stream: Byte for a Chinese need to read two times, the characters for Chinese is actually using the underlying byte stream read two times and then look up the table, return a Chinese character.
Character stream = byte stream + encoded table (not specified according to operating system default code table)
Encoding: Converting text to digital encode
Decoding: Digital conversion to text decode
Flow transmission: Source A--small pipe--large pipe--large pipe--small pipe--the purpose B
Conversion Flow: You can specify the encoding table (not specified in the same native default and its subclasses)
Chinese Gbk-2b/utf-8 (International Standard-Fixed bytes by actual length-Encoder header exists per byte)
Specify to write with UTF-8 to read with UTF-8
* When to use the conversion flow:
The source or target is a byte stream operation that is text data that can be used to improve the operation of the text
Once the text operation involves a specific encoding table, the conversion flow must be used
3. Basic rules of flow operation---Flow can only operate on transmitted data
* Clear source and target land
* Clear whether the data is plain text data--determine the specific system used
Yes: Character stream
No: Byte stream
* Clear Specific equipment
SOURCE Device:
HDD--File
Keyboard--system.in
Memory--Array
Network--socket Stream
Equipment:
HDD--File
Console--system.out
Memory--Array
Network--socket Stream
* Do you need to improve additional features
Need to be efficient (buffer)
Whether the stream needs to be converted
Class 4.File-encapsulates a file or folder that exists/does not exist as an object
* Easy to manipulate the property information of the file or folder
* The file class object can be passed as a parameter to the Stream object
* Common methods of file classes
Construction method
File (file parent, String child)//1,2 Similar
File (string parent, String child)
File (String pathname)
Field
Char Separatorchar system default name delimiter \ \
Char Pathseparatorchar system default Path delimiter
A common approach
1. Get: File name, file path, file size (does not exist on 0B), document modification time
Note File path: relative path and absolute path (starting from the root directory)
2. Create and delete (files, folders)
boolean-Create CreateNewFile () does not exist on the creation, there is not created, and output to different, each time is to overwrite/or continue to write-only the operation of the file or directory, can not manipulate the data inside
Remove Boolean-delete () Remove Windows Delete from Inside Out
Create a single-pole or multi-level catalog (delete a multilevel directory--only the innermost directory is deleted)
File is being accessed cannot be deleted
3. Judging
Whether the file exists (whether the directory/whether the file-for existence) is hidden
4. Renaming Renameto (file dest) renaming files
5. Gets the file and folder name under the specified current directory string[]-list ()
(Contains hidden folders)
Note: When encapsulating a file object, it must be a directory, not a file name
If the directory exists, it returns an array of length 0
6. File filter (emphasis)
List (FilenameFilter filter)-string[]
filenamefilter--file filter (interface) Definition class--Implement FilenameFilter interface
Passing objects of this class to the list () method
Filter method principle: First traverse the directory, put in the array and traverse, satisfies the condition to put in the container,
Converts a collection to an array return
7. Depth variable folder--list of all directories for the specified directory [recursive]
8. Recursion
* Be sure to clear the condition of recursion, otherwise easy stack Overflow
Subclass of the 5.Map interface properties--can be combined with IO technology--map set of properties
Feature: Both the key and the value in the collection are string types
The data in the collection can be saved in the stream, or retrieved from the stream
Function: Typically this collection is used to manipulate profiles that exist as key-value pairs
Profiles: Files that store configuration information for configuring certain applications < key-value pairs, XML, Databases >
Iterate through the elements in the collection:set<string> stringpropertynames ()--Becomes a collection, then an iterator
The combination of properties and flow
List (PrintStream out)--print the collection information directly to the console
Store (OutputStream out, String comments)--stores the collection information on the hard drive--this is called persistence
Two parameters, preceded by the specified position, followed by a string to describe the data-do not write Chinese comments
Modifying key-value pair information stored on the hard disk
Read the file first (make sure it's a key-value pair)--put it in the set--Modify--store
Load (InputStream instream) Read data
Java inside configuration information file named Xx.properties/ini (Windows system)/xml file
Eg: Record the number of times a program is used---using properties--is just a use of properties
Configuration information-usually used to save the application's personalization (Save settings and then turn it off still exists)
Note: The recursive process guarantees that the container is unique, do not define the container inside the method, and pass the parameter container
When defining a method, you need to determine the parameters that are passed in--who's handling
6. Other Stream objects--auxiliary functions
Print stream (do not run out of exception): Printstream--system.out return value
Construction method: Receive file, string path, stream out object
Common method: Provides a way to manipulate various kinds of data printing. The Print method holds the representation of the data
Print (97)--The file is 97,write (97)--will choose the lowest 1B storage will not retain the form
Implementation principle: Converts a number into a string and then writes a string
printwriter--using the Platform default encoding method
Construction method: Receive file, string path, stream out object, write stream
Sequence Flow: sequenceinputstream--merge for multiple streams--only objects that process the source
logical concatenation of input streams-encapsulates multiple streams as a single stream (Sequenceinputstream)
The essence is that the collection is loaded with multiple streams-the last stream return value as the end
Combine multiple sources into one source
Eg: File cut (cut in sequence) + file merge
Note that when you cut a file, the file type and the number of files exist in a configuration file because the merge
Need to use this information.
Object flow: An object stored by objectinputstream/outputstream--in order to be able to hold the object's data--in the file of the hard disk (persisted storage of the object) object flow + file stream with
Object Flow premise: The object to be manipulated must implement serializable (tag interface) to convert an object into a binary digital stream-objects to be stored sequentially in the file--writeobject (object obj), readobject ()
Note: * The storage object simply wants to lengthen the object's life cycle, so it doesn't care about the format of the write-out.
* You must use basic Stream + object flow to translate data into an object when you are reading the file.
Read the object must ensure that the object's class file exists + writes out the file--two exist to be able to read the object successfully--forced transformation
* Write Object--serialization ; Read object--deserialization (similar to encoding and decoding)
* About storage objects--storing non-static member variables of an object (which is transient decorated will not be written into the object file--There is no difference--non-static data does not want to be serialized)
Serializable What is the meaning of the existence of (labeled Interfaces)? ---to the class plus the ID
Storage Object--serialization of the time to get a serialized ID number (corresponding class also has the same ID number), and then the process of deserialization of the Read object, it will detect whether the loaded class and the original class object ID is consistent, inconsistent exception occurs, can not read the object
Different versions of the compiler may compile ID results inconsistent, the workaround itself defines the object serialization ID number
Any-access-modifier static final long serialversionuid = 42L;
randomaccessfile--Random Access file--not part of any IO inheritance system--byte stream
Characteristics
* Read and Write functions for random access files
* The object maintains a byte array and can manipulate the elements in the array by pointers--arrays can be extended--automatically expanded
* You can set and get the position of the current pointer
* In fact, the object will encapsulate byte input stream and byte output stream--as a whole tool object
* operation of random files---can only be files (source/destination)
* Special Structure Method--Specify the mode of operation file (four optional control of Read and write)
* There are many useful methods in this class to read and write basic data types (guaranteed bytes), byte arrays, etc.
* If the file does not exist, it is created and is not created-does not overwrite
* can specify the location of storage and write, random to the file operation Seek (long POS)--Set the current pointer position
If not specified, start writing from the 0-point mark (overwrite if original exists)
* Random Write-can be written anywhere, can start reading from any position
* Random access files require data to be regular, length can be estimated by law
* Small application: Use multiple threads responsible for data write data in different places (use this class to specify where to start writing)
pipedinputstream/pipedoutputstream-pipe flow [applied to multithreading]
Characteristics
* Input stream and output stream can be directly connected to read () <-->write ()
* Pipeline flow reading must read the output of the pipeline flow
Read () [blocking method does not have pipeline output data, wait for]-->write () [No subsequent execution]
The program waits here--the problem is usually handled with multithreading, and the write thread writes out the data wake-up Read thread
* Pipeline flow contains a buffer inside
* Need to call the Connect () method to connect two streams
Datainputstream/dataoutputstream---operation basic data types
Characteristics--preserving the form of the basic data type
* Use combination +inputstream--Read and write types must be consistent
* WRITEUTF ()--readuft () for header information that is automatically added using (encoding and decoding is UTF8 modified version)
The stream object that operates the array--[source and target are in memory]
bytearrayinputstream/bytearrayoutputstream--manipulating arrays with the idea of flow
Characteristics
* variable-length array buffered data in memory
* Do not close the stream (turn off the stream reason: call the underlying resource)--the operating memory does not use the underlying resources
* No IO exception thrown
* Bytearrayinputstream (byte[] buf)--Clear source memory
Bytearrayoutputstream ()--automatically contains an array--you can also specify the size of the buffer
* If the source to be operated on is memory--use Bytearrayinputstream directly
Chararrayreader/chararraywriter
Stringreader/stringreader
7. Common Coding Tables
Ascii-can be 7bit characters
gbk--Chinese Code
unicode--Unified processing method Fixed length encoding--2b
utf-8--not fixed-length encoding, can represent a character up to three bytes
Java Basics Summary--io Summary 2