Java Examples in a Nutshell by David Flanagan This errata page lists errors outstanding in the most recent printing. If you have any error reports or technical questions, you can send them to booktech@oreilly.com. (Please specify the printing date of your copy.) This page was last modified on February 27, 2001. Here's the key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: (This change was made to the 12/98 reprint but please note this information if you have a previous printing of the book.) Under the section "Java Example Online," add the following section regarding licensing information: Licensing Information You may study, use, modify, and distribute these examples for any non-commercial purpose, as long as the copyright notice at the top of each example is retained. If you would like to use the code in a commercial product, you may purchase a commercial use license from the author for a nominal fee. Visit http://www.davidflanagan.com/javaexamples/ for information on obtaining such a license. Please note that the examples are provided as-is, with no warranty of any kind. (10) paragraph 2, line 4: "So, in this examples" should be "So, in this example". (19) line 3: "interatively" should be "interactively". (97) Example 5-7, line 4: * and keyboard events. This is a required or events won't be sent. should read * and keyboard events. This is required or events won't be sent. (124) paragraph 1, line 1: An important features of the Frame class ... should read An important feature of the Frame class ... [161] FileViewer.java, in method setFile: The program went into infinite loop when reading Japanese file. File f; FileReader in = null; try { f = new File(directory, filename); // Create a file object in = new FileReader(f); // Create a char stream to read it int size = (int) f.length(); // Check file size // This size is the file size in byte. ------(1) char[] data = new char[size]; // Allocate an array big enough for it int chars_read = 0; // How many chars read so far? while(chars_read < size) // Loop until we've read it all chars_read += in.read(data, chars_read, size-chars_read); // chars_read is total read size in unicode char ------(2) textarea.setText(new String(data)); // Display chars in TextArea this.setTitle("FileViewer: " + filename); // Set the window title } The author's response: This is an embarrassing mistake, and I am grateful to you for noticing it. In general, I have difficulty catching internationalization errors like this since I do not have a system that uses or can display Japanese text. (And even if I did, I could not develop meaningful examples, since I have no comprehension of the language...) Of the two solutions you propose, I prefer the first one. We should show an example that is guaranteed to work in all cases. However, to improve the efficiency, I would recommend that you modify the example to read more than one line at a time. You use a BufferedReader, which makes reading individual lines efficient, but I fear that appending individual lines to the TextArea is not efficient. So I propose code like this: f = new File(directory, filename); // Create a file object in = new FileReader(f); // Create a char stream to read it char[] buffer = new char[4096]; int len; while((len = in.read(buffer)) != -1) { String s = new String(buffer, 0, len); textarea.append(s); } Note that I have not tested this code, with English text or with Japanese text. I'm just trying to give you an idea of what I'm suggesting. I think this code is properly internationalized, and should always work. If it does not, go ahead and use the code you proposed. (163) paragraph 2, line 6: "it creates and display a FileViewer window" should be "it creates and displays a FileViewer window".