Java Summary 1125/1126

IO style:
1) FileOutputStream FileInputStream byte stream

2) BufferdeOutputStream BufferdeInputStream byte buffer stream 
The byte buffer stream only provides one kind of buffer, and the data transmission for IO is actually implemented according to the underlying basic stream
So you can't directly operate on the file

3)OutputStreamWriter InputStreamReader 字符流
Character stream: byte stream + encoding format (default GBK)
Constructor: public OutputStreamWriter(OutputStream out) ;
Java provides classes that are easier to write
FileWriter(String FileName) FileReader 

4)BufferedWriter(Writer out) BufferedReader
Note: When using byte buffer stream and character stream input, use the flush() method to flush the buffer after each input
BufferedWriter:
public void newLine(); write a newline
BufferedReader
public String readLine(); reads one line at a time

5) DateOutputStream DateInputStream 
All belong to the data stream, which can read and write data of Java basic data types
Construction method:
public DataOutputStream(OutputStream out)
objectname.writeByte...
objectname.readByte...

6)ByteArrayOutputStream ByteArrayIntputStream
The memory operation flow operates on the data in the memory, and the data in the memory disappears as soon as the program ends.
Features: Operate on small files
This stream object can not release resources

7)PrintStream byte print stream PrintWriter character print stream
Features: 1) When copying files, the print stream can only output data
 2) With automatic refresh function
 3) Can operate directly on text files
If the parameter in the constructor of the stream is String or File, you can directly operate on the file
For example: FileInputStream
 FileOutputStream
 FileWriter
 FileReader
Construction method: 
public PrintWriter(String fileName)
public PrintWriter(Writer out,boolean autoFlush)
The second parameter is true, start the startup refresh function
Unique method: 
public void println(String x): prints the string and terminates the line

8) RandomAccessFile random access stream
Instances of this class support accessing and writing to random files
It is not a stream in the actual sense because it inherits from the Object class
Construction method:
public RandomAccessFile(String name, String mode)
Parameter 1: Specify the path of the file
Parameter two: a specified mode: commonly used mode: "rw", this mode can be read or written

9) SequenceInputStream merge streams
Construction method:
public SequenceInputStream(InputStream s1,InputStream s2)
public SequenceInputStream(Enumeration<? extends InputStream> e)
Copy multiple files
Features unique to the Vector collection:
public Enumeration<E> elements()

10) ObjectOutputStream ObjectInputStream serialization stream
Member methods in ObjectOutputStream:
public final void writeObject(Object obj): Write the obj object to the current serialization stream
Member methods in ObjectInputStream:
public final Object readObject(): Reads an object from the current deserialization stream
NotSerializableException (exception that does not implement the serialization interface)

Serialization: Serializeable serialization interface
Serialization and deserialization test points:
1) Put the object ---> stream data or stream data ---> object, the class where the object is located must implement a marker interface: serializable Multithreading has a keyword: synchronization mechanism (synchronized)
2) When the serialized and deserialized version IDs are inconsistent, an exception will occur, so use the production random ID or fixed ID to solve the problem
3) transient: Modified variables will not be serialized...
There are two ways to read the above IO stream:
1) Read byte by byte (character)
int by =0;
while((by = byte(character) object name.read())!=-1){
System.out.println((char)by);
}
2) Read by byte (character) array
byte [] bys = new byte [1024];
int len ​​= 0;
while((len = byte(character) object name.read(bys))!=-1){
System.out.println (bys, 0, len);
}
Buffered Stream aka Efficient Stream
Note: When reading with read() it returns -1 and when reading with readLine() it returns null!
There are two ways to enter the keyboard:
1) Scanner class
2) IO style:
Use BufferedWriter and BufferedReader instead of Scanner and System.out.println
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
String str = br.readLine();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
bw.write(str);
bw.flush();
br.close();
bw.close();
standard input and output streams
There are two fields in the System class:
in:----->InputStream is = System.in ; 
out----->PrintStream ps = System.out ;


Properties集合:

Properties: property collection class, this class inherits from Hashtable<K, V>, this class belongs to the Map collection
The Properties class represents a persistent set of properties.
Properties can be saved in or loaded from a stream. Each key and its corresponding value in the attribute list is a string (generally: it is used as a configuration file, and it is used as a configuration file in MySQL or Oracle)
Construction method:
public Properties(): Creates an empty property list
Unique method:
public Object setProperty(String key,String value)
public Set<String> stringPropertyNames(): Gets the set of all keys in the current property list, the key values ​​are of type String
public String getProperty(String key) searches this property list for the property value with the specified key

Properties can be saved in or loaded from a stream.
Load the data from the file into the property collection: public void load(Reader reader)
Save the data in the property collection to a file: public void store(Writer writer, String comments)
The second parameter: comments: a description of the current property list

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325860197&siteId=291194637