IO Section Index
What is NIO.2?
Part of the OpenJDK project, NIO.2 adds new I/O capabilities designed to simplify Java application development.
Is there a way to read all the items out of an NIO Buffer into an array to pass onto JNI (or for some other purpose)?
The Buffer class has an array() method added in 1.6 that allows you to get the backing buffer in a single call. This can be passed on to native code or to some method that requires an array to wor...more
What's the difference between a BufferOverflowException and BufferUnderflowException?
A BufferOverflowException happens when the target buffer is full and you try to put something into it. A BufferUnderflowException happens when the source buffer is empty and you try to get somethi...more
What's wrong with the following statement: System.out.printf(object.toString())?
The first argument to the printf method is the formatting string. While this will typically display the string you want, if it includes something like a % in it, it won't and will try to interpret...more
How do I get the JAR command to preserve the timestamp of the file in the archive?
Preservation of the timestamp changed with Java 6. Prior versions used the time of extraction.
Is there a limit to the number of simultaneously open zip files?
Prior to Java 6, the limit was 2000. That limit doesn't exist with Java 6.
Are there any predefined file filters for a JFileChooser?
Apart from the accept all filter, until Java 6, there were no predefined filters. Java 6 introduces the FileNameExtensionFilter, allowing you to define one or more types of files for the user to s...more
How can I make a read-only file writable?
Pre-Java 6, you had to either use native code or fork off a platform specific command in a sub-process. With Java 6, there is a setWritable() method.
What's with this new IOError class, when is it thrown?
The Console class has methods to read console input with readLine() and readPassword(). These methods throw IOError instead of IOException. My best guess at why the difference is becasue IOError i...more
How do you get the output of a Java program in a text file instead of getting it on the console?
You can get the output into a file instead of the console / command prompt as follows:
System.setOut(new PrintStream(new FileOutputStream("Test.txt")));
System.out.println("Hello How r u");
No...more
Why did the toURL() method of File get deprecated in Java 6? Should I stop using it now.
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
How do I set the execute attribute of a file?
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 can I accept a password from the console without an echo? - Java 6
How can I accept a password from the console without an echo?
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
What is the deal with the Closeable and Flushable interfaces?
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