Java Reference
In-Depth Information
Table 10-5. Other Java Communications facilties, with examples
Program
Feature
ParallelPrint
Opens a printer and sends a file directly
CommPortModem
Talks to a Hayes-style “AT” command modem on a serial port
CommPortDial.java As above but dials a number
TModem.java
Implements the 1980s era CP/M Modem Protocol to send/receive files
SerialLogger
Event-driven reading/writing, using EventListener model; reads from multiple serial
ports
CommPortThreaded Reading and writing using two Thread s to allow “full duplex” style operation
Given the diminishing use of this API and its planned replacement, we don't discuss these
examples in detail in the topic.
Save User Data to Disk
Problem
You need to save user data to disk in a Java application. This may be in response to
File→Save in a GUI application, saving the file in a text editor, or saving configuration data
in a non-GUI application. You have heard (correctly) that a well-behaved application should
never lose data.
Solution
Use this five-step plan, with appropriate variations:
1. Create a temporary file; arrange for it to be removed automatically with de-
leteOnExit(true) .
2. Write the user data to this file. Data format translation errors, if any, will be thrown
during this process, leaving the previous version of the user's data file intact.
Search WWH ::




Custom Search