Master the inheritance system of InputStream, OutputStream, Reader, and Writer.
1. What is a Bit, what is a Byte, and what is a Char? How long are they
The answer
Byte is the smallest unit of data that a computer can operate on. The value consists of eight bits (-128-127). Char is the smallest unit of data that a user can read and write. In Java, the value consists of 16 bits (0 to 65535). A bit is the smallest unit that a computer can recognize only 0 or 1. 8 bytes are the characters shown to the computerCopy the code
2. What are streams, which are divided into two streams according to the unit of transmission, and what is their parent stream called the transmission of data
The answer
InputStream OutputStream Character stream: Reader WriterCopy the code
3. The flow can be divided into two types according to the direction of transmission
The answer
Input and output relative to program InputStream InputStream OutputStream OutputStreamCopy the code
4. According to the realization of functions, which two kinds are divided into, respectively illustrate
The answer
Node stream, processing stream Node stream: OutputStream Processing stream: OutputStreamWriterCopy the code
5. What stream is BufferedReader, what is it mainly used for, and what are the classic methods in it
The answer
A buffered stream in a processing stream that stores the read in memory, with the readLine () methodCopy the code
6. What is a node stream and what is a process stream, what are their uses, and what are the characteristics of the creation of a process stream
The answer
A node stream is directly connected to a data source and is used for input or output processing streams: the constructor of a node stream must pass in a subclass of the node stream to process on top of it, extending some of its functionalityCopy the code
7. If I want to do a lot of byte stream reading from hard disk, which stream should I use? Why
The answer
BufferedInputStream Using buffered streams can reduce damage to your hard driveCopy the code
8. If I want to print different types of data to a data source, which stream is the most suitable? Why
The answer
Printwriter can print a variety of data typesCopy the code
9. How to change the output of our console to an output file? What is this technique called
The answer
SetOut (printWriter,printStream) redirectsCopy the code
10. When do you use serializable in your Java code? How to implement Java serialization?
The answer
To write an object to or read from a data source using Serializable, you need to implement the Serializable interfaceCopy the code
11. How to convert an output byte stream to an output character stream and say its steps
The answer
New OutputStreamWriter (New FileOutputStream (File File));Copy the code
12. Which two streams are used to output or read data and strings, including primitive types, sequentially to or from the data source
The answer
DataInputStream DataOutputStream
Copy the code
13. Which two streams are used to write an object to or read from a data source
The answer
ObjectInputStream ObjectOutputStream
Copy the code
14. What is object serialization, what is deserialization, and what needs to be done to realize object serialization
The answer
Object serialization, the object in binary form saved on the hard disk deserialization; Convert binary files into objects to read implement serialIZABLE interface do not want to put fields on the hard disk add transientCopy the code
15. Which keyword should be used if you don’t want to store a field’s data on hard disk during object serialization?
The answer
Transient keywordCopy the code
16. When implementing serialization interface, a serialVersionUID field is generated. What is it called and what is it used for
The answer
Is the version number, and you want to keep the same version number to serialize in case of serialization errorsCopy the code
17. What does read() in InputStream return? What does read(byte[] data) mean
The answer
Read (byte [] data) Stores the read bytes in this array and returns the number of parameters in the array. Read byte Read byte character Read characterCopy the code
Write (byte b[], int off, int len) OutputStream
The answer
Write passes the specified Byte to the data source. Byte B [] is the Byte array. B [off] is the first character passed in. B [off+len-1] is the last character passed inCopy the code
19. Streams usually do not need to be closed. If they are closed, what method is used?
The answer
Once opened, a stream must be closed. A processing stream called using the close method ina finally statement block (finally statements must be executed) closes the processing stream. Multiple streams calling each other close only the outermost streamCopy the code
20. All flows in Java can be divided into several broad categories, what are their names, and what do they stand for
The answer
Byte InputStream byte OutputStream OutputStream character InputStream Reader character OutputStream Writer all streams are subclasses of the four streamsCopy the code
21. Describe common I/O streams
The answer
InputStream,OutputStream,FileInputStream,FileOutputStream,BufferedInputStream,BufferedOutputStreamReader,WriterBufferedR eader,BufferedWriterCopy the code
22. How does an IO stream read files?
The answer
Get the File path using the File object, add the File to the stream Reader, process the Reader using the BufferedReader stream, define a string, and loop through the File. File File = new File("d:/spring.txt"); try {Reader reader = new FileReader(file); BufferedReader buffered = new BufferedReader(reader); String data = null; while((data = buffered.readLine())! =null){System.out.println(data); }} catch (FileNotFoundException e) {e.printStackTrace(); } catch (IOException e) {e.printStackTrace(); }Copy the code
23. Tell me what you understand about IO streams
The answer
Io streams are mainly used to deal with input and output problems. The commonly used I/O streams include InputStream, OutputStream, Reader, Writer, and so onCopy the code
JAVA IO streams and readLine methods
The answer
Java IO streams handle input/output problems, and readLine is a method in BufferedReader that reads a line.Copy the code
25. What is used to dynamically write objects to disk, and what interfaces are to be implemented.
The answer
ObjectInputStream requires the Serializable interface to be implementedCopy the code
26.FileInputStream is created in several different ways.
The answer
A FileInputStream is a subclass of InputStream. By definition of the interface, a subclass can create a FileInputStream.Copy the code
Copyright notice: This article is the original article of CSDN blogger “Java Sword to travel the World”, according to CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement. Original link: blog.csdn.net/baidu_37107…