Page 649 - Introduction to Programming with Java: A Problem Solving Approach
P. 649

                15.6 Text File Data Format Versus Binary File Data Format 615
 Example input file, family.txt: Our Family
We have a dog, Barkley. Barkley is a good dog. She sleeps a lot
and digs up the grass. We feed her twice a day.
We have two kids, Jordan and Caiden. They're girls. They like to
eat, cry, and play. We like them a lot.
Resulting output file, family.html: <html>
<head>
<title>Our Family</title>
      </head>
<body>
<h1>Our
<p>
We have
Family</h1>
a dog, Barkley. Barkley is a good dog. She sleeps a lot
and digs up the grass. We feed her twice a day.
<p>
We have two kids, Jordan and Caiden. They're girls. They like to
eat, cry, and
</body>
</html>
plAapy.aWge olikePtDheFm aElnoth. ancer
First line of input file appears twice in output file.
  This works, but to conform to strict HTML standards, Web pages should have a </p> at the end of each paragraph.
   Figure 15.7 Example input file for the HTMLGenerator program and its resulting output file
Note Figure 15.7’s second callout. To conform to strict HTML standards, you should insert a </p> tag at the end of each paragraph. However, many current Web pages conform only to loose HTML standards, not to strict HTML standards. Current browsers handle both strict and loose Web pages, but future browsers will probably handle only strict Web pages. An end-of-chapter exercise asks you to improve the HTMLGen- erator program so that it generates </p> end tags at the end of every paragraph.
15.6 Text File Data Format Versus Binary File Data Format
This section compares the text format used in text files with the native binary format used in binary files and
object files.
Text Format
Text file data is stored using eight-bit American Standard Code for Information Interchange (ASCII) values. Since the ASCII character set is a universal standard, ASCII characters can be read by almost any text edi- tor5 or word processor, and they can be read by programs written in any language, not just Java.
5 Exception: Microsoft Notepad recognizes only \r\n as a line terminator. Thus if Notepad tries to read a Java text file that uses \n for line termination, it displays each \n as an unrecognized character (􏰀) and does not generate a new line.
  

































































   647   648   649   650   651