IO Section Index | Page 2
The toURL() method of File does not properly escape characters that aren't valid in a URL. You can write better code today without waiting for Java 6 by calling the toURL() method after calling to...more
Assuming you are on a platform that supports the attribute, you can call the setExecutable() method of File. Of course, you'll need to wait for Java 6 to do this. Prior versions of standard Java d...more
How do I print high-order characters to the console? Whenever I use System.out.println(), it chops off anything above seven bits.
System.out is an OutputStream. You need to work with a Writer object. With Java 6, you would use the printf() method of the new Console class, which is returned by the console() method of System.more
How can I accept a password from the console without an echo?
Added to JDK 5.0, you can call the defaultCharset() method of the CharSet class, found in the java.nio.charset package. This is apt to depend upon the locale and character set of the underlying sy...more
Typically, you would create a FileOutputStream and pass it to the PrintStream constructor. Starting with 5.0, you can pass the File or String name for file directory to the PrintStream constructor.more
The Appendable interface and its append() methods are implemented in classes that support adding characters to the end of an object, typically a stream. Indirectly used through the Formatter class...more
The ability to close() or flush() an object (typeically a stream) has been factored out into single method interfaces, Closeable and Flushable, respectively. Given that you sometimes need to opera...more
JDK 5.0 added support for code points above U+FFFF. Additional information is available from Supplementary Characters in the Java Platform.more
The java.util.Scanner constructor takes a file, channel, input stream, or reader as an argument and lets you read an int (with nextInt()), read a line (with nextLine()), or any other data type wit...more
JDK 5.0 provides built in support for printing tables. Just call the print() method of JTable. Here's an example of such. import javax.swing.*; import java.awt.*; import java.awt.event.*; impor...more
There are at least three ways to generate formatted output: Use the format() method of an instance of Formatter. Use the format()/printf method of an OutputStream, as in System.out.format("The t...more
The java.util.Formatter class was introduced in JDK 5.0 and offers locale-sensitive formatting of numbers and strings.
The StringBuilder class was introduced with JDK 5.0. Essentially, a StringBuffer is a thread-safe version of StringBuilder. If you are only adding/removing characters from a single-thread, the Str...more
Until someone provides a PDF print service, you can't. The standard runtime does not provide one. Just because you can specify a DocFlavor of PDF (DocFlavor.STRING.INPUT_STREAM.PDF) doesn't mean y...more