201621123016 Java programming 12th Week of study summary

Source: Internet
Author: User
Tags save file

1. Summary of this week's study

1.1 Summarize multiple streams and file-related content in the way you like (mind mapping or other).

2. System-oriented integrated design-Library management system or shopping cart

Use streams and files 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?

I use ObjectInputStream and Fileinputstream,objectoutputstream and FileOutputStream to read and save file information directly, The information stored in it is an array of type custom type user, in which the information for all users is saved.

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 use these interfaces with classes?

The ObjectInputStream and Fileinputstream,objectoutputstream and FileOutputStream classes are used in the file, and these classes are used to store information about a user class directly. It is best to inherit the serializable interface in the class, which ensures that the file is read without errors.

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

3. Code Volume statistics

3.1 Count the amount of code completed this week

The weekly code statistics need to be fused into a single table.

Week Time Total code Amount New Code Volume total number of files number of new files
2 625 625 99 99
3 1429 804 113 14
4 3354 1925 223 110
5 3751 397 241 18
6 4369 31] 80 -161
7 4998 629 78 -2
8 5590 592 87 9
9 5751 161 89 2
11 6101 350 97 8
12 6495 394 104 7
13 6786 291 108 4
Option: 4. Flow and Document Learning Guide (the job content is all selected at the bottom) 1. Character stream with text file: Use PrintWriter (write) BufferedReader (read)

Writes the Student object (property: Int id, String name,int age,double grade) to the file Student.data, read from the file display.

1.1 Generated three student objects, using PrintWriter's Println method to write 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)

This picture is cut in the school's lab, so it's not the same as other diagrams.

1.2 What is the size of the generated file (using the right-click File Properties view)? Analyze the file size

In which 1000000 of the user information is deposited to get a large size of 20.00Mb. This means that each line contains 21 bytes of sexual interest, one letter for a large size of one byte.

1.3 If the println method of PrintWriter is called, but not close at the back. What is the file size? Why?

The size of the file is 0. The file information is not saved to the file because it is not closed.

2. Buffer Stream

2.1 Use PrintWriter to write 10 million lines to a file (whatever it is), and then compare the speed (read only, not output) of reading data from the file using BufferedReader with scanner, which method is 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

This picture is cut in the school's lab, so it's not the same as other diagrams.

Using BufferedReader will save the contents of the file to the memory and then read, and scanner This is read directly from the file so use BufferedReader read faster.

2.2 Replace the PrintWriter with BufferedWriter to see if the speed of writing to the file has improved. Record the elapsed time of both. Try to analyze the reason.

3. Character encoding

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)

It could be the operating system. My output is fine.

Using GBK encoded output will cause an error.

Using UTF-8 to encode the output without error.

3.2 Writing method Convertgbk2utf8 (string src, string dst), you can convert the GBK encoded source file src to a UTF8 encoded destination file for DST.

201621123016 Java Programming 12th Week of study summary

Related Article

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.