IO Section Index | Page 4
How can I read an Microsoft Excel file from Java?
There is no built in support for this. While you can create an ODBC DSN and use the JDBC bridge to the file, this can be a nuisance to do. Instead try the open source ExcelRead package, which allo...more
How to make a file read only?
For any type of file, just use the setReadOnly() method of File to mark a file as read-only. There is no argument to make it writable once it is read-only.
What's up with the CharSequence/CharBuffer in 1.4 beta 3? None of the examples work any more.
The beta 3 release of Java 1.4 broke the class. See bug 4510323 for a description of the problem. Hopefully, this will be fixed for the first non-beta release.more
How do I initialize a JTextArea from an input file?
The JTextComponent provides a read() method to initialize the text component:
JTextArea ta = new JTextArea();
Reader reader = new FileReader(filename);
ta.read(reader, null);
The sec...more
None of the NIO examples that use character buffers work with 1.4 beta 3. What's up?
This is bug 4510323. You'll need to wait to see when it get fixed...
How can I show a progress bar while reading a file?
Here's a simple example of monitoring file read progress
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
impo...more
How do I create a Selector (java.nio.channels)?
While the Selector class is abstract, you can create one by calling the static open() method. This will create an instance of a Selector subclass. Behind the scenes, this is done through the selec...more
Where can I learn to use the Java 1.4 regular expression package?
The Java Developer Connection provides a tutorial on the package at http://java.sun.com/jdc/technicalArticles/releases/1.4regex/.more
How can I save an image to disk in a standard image format?
The javax.imageio package provides this for you in Java 1.4. Previousl versions had no standard support, though you could add third party libraries to standard Java for this.
BufferedImage ou...more
Do I have to synchronize read-only access to a text file?
My servlet reads the contents of a text file which I access using a File object.
What issues are involved when this file is read concurrently by several different threads? Do I have to synchronize...more
How can I redirect the output of session.setDebug(true) so that I can capture it in the program that uses it?
The messages are hardcoded to go to System.out. The best you can do is redirect System.out to a ByteArrayOutputStream:
session.setDebug(true);
ByteArrayOutputStream os = new ByteArrayOutputStream...more
How do I convert between ByteBuffer and a CharBuffer using Java 1.4?
The java.nio.charset package include character set converters for you. To go from ByteBuffer to CharBuffer, you would do something like the following:
ByteBuffer buffer = ...
Charset charset = C...more
How do I map a file into memory using the New I/O capabilities in Java 1.4?
FileInputStream input = new FileInputStream(filename);
FileChannel channel = input.getChannel();
int fileLength = (int)channel.size();
MappedByteBuffer buffer =
channel.map(FileChannel.MAP_RO,...more
How are the mark() and reset() methods used with InputStream classes?
How are the mark() and reset() methods used with InputStream classes?
How can I detect if there is a floppy in the floppy drive using Java?
How can I detect if there is a floppy in the floppy drive using Java?
javaw.exe takes over with the "No disk" dialog, even when I catch a Security Exception. How does one suppress this dialog?????