The The following new methods were added to New One new class is provided: The following new methods were added to Constructors were added to the following class: The behavior of the following method was modified:java.io.File
class is now
superceded by java.nio.file.Path
,
java.nio.file.Files
and the rest of the
java.nio.file package.
File
:
toPath()
- returns a java.nio.file.Path object constructed from the
abstract path.
java.nio
A new
BufferPoolMXBean
interface for managng a buffer pool.java.nio.channels
Five new interfaces and six new classes to support multicasting and
asynchronous I/O:
New constructors and methods added to existing channel classes and
interfaces to support multicasting and asynchronous I/O:
AsynchronousByteChannel
- a asynchronous channel that
can read and write bytes.AsynchronousChannel
- a channel that suports ascynchronous I/O operations.CompletionHandler
- a handler for consuming the result of an asynchronous I/O
operation.MulticastChannel
- a network channel that supports Internet Protocol (IP)
multicasting.NetworkChannel
- a channel to a network socket.
AsynchronousChannelGroup
- a grouping of asynchronous
channels for the purpose of resource sharing.
AsynchronousFileChannel
- an asynchronous channel fo
rreading, writing, and manipulating a file.AsynchronousServerSocketChannel
- an asynchronous
channel for stream-oriented listening sockets.
AsynchronousSocketChannel
- an asynchronous channel for
stream-oriented connecting sockets.MembershipKey
- a token representing the membership of an Internet Protocol (IP)
multicast group
Channels.newInputStream(AsynchronousByteChannel)
-
the channel from which bytes will be read.Channels.newOutputStream(AsynchronousByteChannel)
- constructs a stream that writes bytes to the given channel.DatagramChannel.bind(SocketAddress)
- binds the
channel's socket to a local address.DatagramChannel.getLocalAdress()
- returns the
socket address that this channel's socket is bound to, or null if
the socket is not bound.FileLock(AsynchronousFileChannel, long, long,
boolean)
- initializes a new instance of this
class.FileLock.acquiredBy()
- returns the channel upon whose file this lock was acquired.FileLock.channel()
- returns the file channel upon whose file this lock was
acquired.ServerSocketChannel.bind(SocketAddress)
- binds
the channel's socket to a local address and configures the socket
to listen for connections.ServerSocketChannel.bind(SocketAddress,int)
-
binds the channel's socket to a local address and configures the
socket to listen for connections.ServerSocketChannel.getLocalAdress()
- returns the
socket address that this channel's socket is bound to,ServerSocketChannel.setOption(SocketOption, T)
-
sets the value of a socket option.ServerSocketChannel.getOption(SocketOption)
-
returns the value of a socket option.ServerSocketChannel.supportedOptions()
- returns a
set of the socket options supported by this channel.SocketChannel.bind(SocketAddress)
- binds the
channel's socket to a local address.SocketChannel.getLocalAddress()
- returns the
socket address that this channel's socket is bound to, or null if
the swocket is not bound.SocketChannel.setOption(SocketOption<T> name, T value)
- sets
the value of a socket option.SocketChannel.supportedOptions()
- returns a set
of the socket options supported by this channel.SocketChannel.showDownInput()
- shutdown the
connection for reading without closing the channel.SocketChannel.showDownOutput()
- shutdown the
connection for writing without closing the channel.SocketChannel.getRemoteAddress()
- returns the
remote address to which this channel's socket is connected.nio.channels
API to support File I/O:
SeekableByteChannel
byte channel interface supports a file channel that maintains a
current position and allows that position to be changed.FileChannel.open(Path, OpenOption...)
- opens or
creates a file, returning a file channel to access the file.FileChannel.open(Path, Set<? extends OpenOption>
Fileattribute<?>)
- opens or creates a file,
returning a file channel to access the file.java.nio.channels.spi
java.nio.channels.spi
package enables developers to define a new selector provider using
SelectorProvider
or a new asynchronous channel provider using
AsynchronousChannelProvider
.java.nio.file
java.nio.file
package defines interfaces and classes to access files, file
attributes and file systems. This package supercedes the
java.io.File
class.
The File I/O lesson in the
Java
Tutorial explains the new API.
java.nio.file.attribute
java.nio.file.attribute
package defines interfaces and classes for providing access to file
and file system attributes.java.nio.file.spi
java.nio.file.spi
package defines interfaces and classes for defining new file system
providers or file type detectors.Enhancements in Java SE 6
java.io
Console
-
Contains methods to access a character-based console device. The
readPassword()
methods disable echoing thus they are
suitable for retrieval of sensitive data such as passwords. The
method System.console()
returns the unique console associated with the Java Virtual
Machine.File
:
getTotalSpace()
returns the size of the partition in bytesgetFreeSpace()
returns the number of unallocated bytes in the partitiongetUsableSpace()
returns the number of bytes available on the partition and includes
checks for write permissions and other operating system
restrictions
setWritable(boolean writable, boolean ownerOnly)
and
setWritable(boolean
writable)
set the owner's or everybody's write
permission
setReadable(boolean readable, boolean ownerOnly)
and
setReadable(boolean
readable)
set the owner's or everybody's read
permission
setExecutable(boolean executable, boolean ownerOnly)
and
setExecutable(boolean
executable)
set the owner's or everybody's execute
permissioncanExecute()
tests the value of the execute permission
IOException
supports exception chaining via the addition of the new
constructors
IOException(String, Throwable)
and
IOException(Throwable)
.
File.isFile()
Windows implementation has been modified to always return
false
for reserved device names such as CON, NUL, AUX,
LPT, etc. Previously it returned true
, which customers
considered a bug because it was inconsistent with behavior for
devices on Unix.java.nio
java.nio.channels.SelectorProvider
implementation that is based on the Linux epoll event notification
facility is included. The epoll facility is available in the Linux
2.6, and newer, kernels. The new epoll-based
SelectorProvider
implementation is more scalable than
the traditional poll-based SelectorProvider
implementation when there are thousands of SelectableChannel
s
registered with a Selector
.
The new SelectorProvider
implementation will be used
by default when the 2.6 kernel is detected. The poll-based
SelectorProvider
will be used when a pre-2.6 kernel is
detected.sun.nio.ch.disableSystemWideOverlappingFileLockCheck
controls whether java.nio.channels.FileChannel.lock()
checks whether regions are locked by other instances of
FileChannel
. Unless this system property is set to
true
, FileChannel.lock()
will throw an
OverlappingFileLockException
if an application attempts
to lock a region that overlaps one that is locked by another
instance of FileChannel
. The system property exists to
provide compatibility with previous releases which do not implement
the JVM-wide overlapping file lock check.Enhancements in J2SE 5.0
java.nio
javax.net.ssl.SSLEngine
was added. The existing J2SDK 1.4.0 secure communication
infrastructure, javax.net.ssl.SSLSocket
,
was based on the I/O model of java.net.Socket. The
SSLEngine
class abstracts away the I/O model, and
leaves developers free to secure communication pathways using
alternate types of I/O. SSLEngine
can be combined with
the New I/O APIs to create implementations such as secure blocking
or non-blocking SocketChannel
s. For details see the
JSSE Reference
Guide.Enhancements in Java 2 SDK v1.4
java.io
FileInputStream
and FileOutputStream
classes, getChannel
methods have been added to return
the underlying FileChannel
object, and the
close
methods have been revised to close the
underlying channel.RandomAccessFile
class, a getChannel
method has been added and the
close
method has been revised to close the underlying
channel. The RandomAccessFile
constructors now support
the mode characters "s" and "d" to allow the
specification, at file-open time, of synchronous writes or
synchronous-data writes.InputStreamReader
and OutputStreamWriter
classes, constructors have been added that take a stream and a
Charset
object, and the getEncoding
methods have been revised to return the historical name of the
encoding being used. Constructors to InputStreamReader
and OutputStreamWriter
have been added that take
existing CharsetDecoder
and
CharsetEncoder
objects, respectively.java.nio
Previous Enhancements
java.io.File
class.java.io
package.