IO Section Index | Page 2
How do I find out the default character set for the JVM?
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
How do I print to a file?
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
Why would I want to use the Appendable interface?
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
How do I do C-style formatted printing, like with printf?
The java.util.Formatter class was introduced in JDK 5.0 and offers locale-sensitive formatting of numbers and strings.
How do I print a JTable?
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
How do I read formatted input from the command line?
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
How do I use the java.util.Formatter class to format output?
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
What's the difference between a StringBuffer and StringBuilder?
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
Why can't I use Unicode supplementary characters in JDK 1.4?
JDK 5.0 added support for code points above U+FFFF. Additional information is available from Supplementary Characters in the Java Platform.more
How do I print a PDF file using the new JDK 1.4 printing API?
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
How do I use the java.nio.channels package to do non-blocking I/O operations in Java 1.4?
See New I/O Functionality for Java 2 Standard Edition 1.4 and Master Merlin's new I/O classes for examples of using the new capabilities.more
What options are available for creating and editing PDF files?
This is a list of some PDF Libraries:
PJ free by Ethymon
iText free by B.Lowagie &P.Soares
retepPDF free by P.T.Mount
PDFLib by PDFlib GmbH
Faceless PDF library by Faceless.Org
Obviously, if...more
How can I correctly parse CSV ( comma separated values ) files? StringTokenizer doesn't seem to fit many conditions.
Ian Darwin has two classes ( CSV.java and CSVRE.java ) to handle CSV files in his Java Cookbook, including a way with regular expressions. You can download the code from his site, probably best t...more
How can I get the path of a JarEnrty?
java.util.jar.JarEntry is a subclass of java.util.zip.ZipEntry. If you use the getName() method on your JarEntry object, you will get the full name of the entry, including its path (relative or ab...more
Can I read individual keystrokes from System.in?
Short of using JNI, you cannot.