1. Study summary 1.1 This week summarize multiple streams and file-related content in the way you like (mind map or other).
2. System-oriented integrated design-Library management system or shopping cart use flow and documentation to transform your library management system or shopping cart. 2.1 A brief description of how to use streams and files to transform your system. What is the format of the data in the file? 2.2 Brief description of what interfaces and classes are used in the file reading and writing section of the system with the stream associated with the file? Why do you want # # #用这些接口与类? 2.3 Read and write file-related code. Critical lines need to be annotated. 3. Code volume Statistics 3.1 Statistics the amount of code completed this week requires that the weekly code statistics be fused into a single table.
Option: 4. Flow and Document Learning Guide (the job content is all selected at the bottom) 1. Character streams and text files: using
PrintWriter(写),BufferedReader
(read) will
Student
Object (property: Int id, String name,int age,double grade) write to File # # # #student. Data, read from the file display. 1.1 Generated three student objects, using
PrintWriter
Of
println
Method is written to Student.txt, each line # # #一个学生, and each student's attribute is separated by |. Read the data using Scanner or # # #BufferedReader将student. txt. (Key code, occurrence number)
1.2 What is the size of the generated file (using the right-click File Properties view)? Analyze the file size
A: The resulting size file is 48 bytes.
1.3 If you call
PrintWriter
Of
println
method, but not at the back
close
。 What is the file size? Why?
A: The file size becomes 0 bytes, because the close () method is used when the stream is closed, the flush () method is called during this process, writer
and outputStream
all buffers in the chain are flushed and the data is lost.
2. Buffer Stream 2.1 use
PrintWriter
Write 10 million lines to the file (whatever it is), then compare the use of # # #BufferedReader与使用Scanner从该文件中读取数据的速度 (read only, not lose # # #出), which method is used fast? Intercept the test source code, the number of the study. Please analyze the reasons in detail. Tip: You can use JUNIT4 to compare run times
A: Using BufferedReader is faster because it has a larger buffer and can reduce the number of operations on the file when used.
2.2 Will
PrintWriter
Into
BufferedWriter
To see if the speed of writing to the file has improved. Record the elapsed time of both. Try to analyze the reason.
A: Using BufferedWriter to write files is faster because of the use of buffering technology.
4. Byte stream, binary file:
DataInputStream
,
DataOutputStream
、
ObjectInputStream
4.1 References
DataStream
Directory-related code that attempts to write data from three student objects to a file and then read it out and display it. (Key code, occurrence number)
The results of the operation are as follows:
4.2 The file generated here and Topic 1 generated files why not the same? How large is the generated file? Analysis # # #该文件大小? Compare the file size to the file generated by topic 1 is it big or small, why?
A: Larger than the file generated by topic 1, because using UTF-8 encoding to store files, Chinese characters accounted for a larger number of bytes.
Java Week 12--streams and files