jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

View:
IO FAQ Home Page

FAQ Manager is guru John Zukowski PREMIUM.

Reading, writing, and filtering, bytes, characters, and objects, Java provides streams for them all. Or, add your own. [FAQ Previously managed by Tim Rohaly].

What's New

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)?
Java:API:IO:NIO
John Zukowski PREMIUM, Jun 3, 2007
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...
What's the difference between a BufferOverflowException and BufferUnderflowException?
Java:API:IO:NIO
John Zukowski PREMIUM, Jun 3, 2007
A BufferOverflowException happens when the target buffer is full and you try to put something into it. A BufferUnderflowException happens when the source...
What's wrong with the following statement: System.out.printf(object.toString())?
Java:API:IO
John Zukowski PREMIUM, Jun 3, 2007
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...

How do I get the JAR command to preserve the timestamp of the file in the archive?
Java:API:IO:Compression:Jar
John Zukowski PREMIUM, Oct 1, 2006
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?
Java:API:IO:Compression:Zip
John Zukowski PREMIUM, Oct 1, 2006
Prior to Java 6, the limit was 2000. That limit doesn't exist with Java 6.
How can I make a read-only file writable?
Java:API:IO:File System
John Zukowski PREMIUM, Jun 30, 2006
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?
Java:API:IO
John Zukowski PREMIUM, Jun 30, 2006
The Console class has methods to read console input with readLine() and readPassword(). These methods throw IOError instead of IOException. My best guess...
Are there any predefined file filters for a JFileChooser?
Java:API:Swing:Widgets, Java:API:IO:Filters
John Zukowski PREMIUM, Jun 30, 2006
Apart from the accept all filter, until Java 6, there were no predefined filters. Java 6 introduces the FileNameExtensionFilter, allowing you to define...
How do you get the output of a Java program in a text file instead of getting it on the console?
Java:API:IO
pratheesh k p , Mar 2, 2006
You can get the output into a file instead of the console / command prompt as follows: System.setOut(new PrintStream(new FileOutputStream("Test.t...
Why did the toURL() method of File get deprecated in Java 6? Should I stop using it now.
Java:API:IO:File System
John Zukowski PREMIUM, Jan 22, 2006
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...
How do I set the execute attribute of a file?
Java:API:IO:File System
John Zukowski PREMIUM, Dec 31, 2005
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...
How do I print high-order characters to the console? Whenever I use System.out.println(), it chops off anything above seven bits.
Java:API:IO
John Zukowski PREMIUM, Dec 5, 2005
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...
How can I accept a password from the console without an echo?
Java:API:IO
John Zukowski PREMIUM, Dec 5, 2005
Prior to Java 6, you couldn't. In Java 6, you have a readPassword() method in the new Console class.
How do I find out the default character set for the JVM?
Java:API:Internationalization:Character Sets, Java:API:IO:NIO
John Zukowski PREMIUM, Jul 31, 2005
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...
How do I print to a file?
Java:API:IO
John Zukowski PREMIUM, Jul 31, 2005
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...
Why would I want to use the Appendable interface?
Java:API:IO
John Zukowski PREMIUM, Jul 31, 2005
The Appendable interface and its append() methods are implemented in classes that support adding characters to the end of an object, typically a stream....
What is the deal with the Closeable and Flushable interfaces?
Java:API:IO
John Zukowski PREMIUM, Jul 31, 2005
The ability to close() or flush() an object (typeically a stream) has been factored out into single method interfaces, Closeable and Flushable, respectively....
Why can't I use Unicode supplementary characters in JDK 1.4?
Java:API:IO, Java:Language
John Zukowski PREMIUM, Jun 30, 2005
JDK 5.0 added support for code points above U+FFFF. Additional information is available from Supplementary Characters in the Java Platform.
How do I read formatted input from the command line?
Java:API:IO
John Zukowski PREMIUM, Jun 30, 2005
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...
How do I print a JTable?
Java:API:Swing:Widgets, Java:API:IO:Printing
John Zukowski PREMIUM, Jun 30, 2005
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...
« previous beginning next »


Ask A Question



Related Links

IO Forum

I/O in Java 2 SDK

Java I/O package documentation

Lesson: Reading and Writing (Sun Tutorial)

jGuru Serialization FAQ

Wish List
Features
About jGuru
Contact Us

 



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers