Study Number: 201621123032 Java programming 12th Week of study summary

Source: Internet
Author: User

1: Study Summary of the Week 1.1: summarize multi-stream and file-related content in the way you like (mind map or other).

2: System-oriented integrated design-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?

Compared to the last book information stored in the HashMap, this time the use of streams and files to put the book information in the file, but also from the file read information.
The file format is:. txt.

2.2: Brief description of the file read and write section of the system uses the stream and file-related interfaces and classes? Why use these interfaces with classes?

Use the character output stream: Filewriter,bufferedwriter. Character input stream: FileReader, BufferedReader

    • FileWriter: Create file character output stream
    • BufferedWriter: encapsulating the output stream with buffered data streams
    • FileReader: Create file character input stream
    • BufferedReader: encapsulating an input stream with buffered data streams
      In order to read the information from the file and write the new information to the file.

      2.3: Read and write file-related code. Critical lines need to be annotated.

      Store the contents of the book in a file:

Query a book information:

Delete a line of information in a file: Store the information in a dynamic array and rewrite the file information.

Some features are not yet

There are implementations.
Operation Result:

3: Code Volume statistics
Week Time Total code Amount new increase in code volume Total Folder Add new Folder
1 114 114 11 11
2 520 50W 16 6
3 1089 569 22 6
5 1425 336 29 7
6 1819 394 31 2
7 2987 1168 54 23
8 5437 2450 79 25
9 5695 258 84 5
10 6680 985 102 18
11 6935 255 111 9
12 7401 466 123 12
13 8899 1498 141 18

4: Optional 4.1: Character stream with text file: Using PrintWriter (Write), BufferedReader (read) 1: Generated three student objects, Use PrintWriter's println method to write to Student.txt, one student per line, and each student's attribute separated by |. Use scanner or BufferedReader to read the Student.txt data. (Key code, occurrence number)


Operation Result:

2: How much is the generated file size (using the right-click File Properties view)? Analyze the file size


16 bytes per line
Num:2, Name:4, Age:2,grade:5 separator: 3

4.2: Buffer Stream 1: Use PrintWriter to write 10 million lines to the file (whatever content), and then compare the use of BufferedReader and using scanner to read the data from the file speed (read only, not output), 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

Using BufferedReader faster, bufferedreader using buffering can reduce the number of Io, so the read speed is faster.

Time Comparison:

4.3:1: Existing EncodeTest.txt file, contains some Chinese, the file is encoded using UTF-8. Use FileReader and BufferedReader to read the EncodeTest.txt text into and out. Do you have garbled characters? Why does it have garbled characters? How to solve? (Key code, occurrence number)

will be garbled, because the file is UTF-8 encoded, but the read encoding is used GBK.

Workaround: Use UTF-8 encoding whenever code reads

Operation Result:

Study Number: 201621123032 Java programming 12th Week of study summary

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.