NIO « File Input Output « Java Articles

Home
Java Articles
1.Build Deploy
2.Class
3.Core Library
4.Data Types
5.Database JDBC
6.Design
7.Development
8.File Input Output
9.Graphics Desktop
10.J2EE Enterprise
11.J2ME Wireless
12.JVM
13.Language
14.Library Product
15.Network
16.Security
17.SOA Web Services
18.Test
19.Web Development
20.XML
Java Articles » File Input Output » NIO 
The support for I/O multiplexing is a new feature of Java 1.4. It builds on two features of the Java NIO (New I/O) API: selectors and non-blocking I/O. The article "Introducing Nonblocking Sockets" provides a good introduction to these two features.

Editor's Note: Along with exotic and ambitious proposed features like the Java Module System, closures, and language-level XML support, do you suppose Java 7 will provide us a reliable file-copy method? It could happen, as a JSR for "More New I/O APIs for the Java Platform" appears to be a likely candidate for inclusion in Java 7. In this installment of The Open Road, Elliotte Rusty Harold takes a detailed look at the current state of the NIO2 spec and how it will, and sometimes won't, help you work with files.

If you are asked to write a highly scalable Java-based server, it won't take long to decide to use the Java NIO package. To get your server running, you will probably spend a lot of time reading blogs and tutorials to understand the thread synchronization needs of the NIO Selector class and to deal with common pitfalls. This article describes the basic architecture of a connection-oriented NIO-based server. It takes a look at a preferred threading model and discusses the basic components of such a server.

Back in January 2000, while many people were arguing about whether the year 2000 was the last or first year of the century, life began for JSR 51 as an approved Java Specification Request (JSR). The name of that JSR is New I/O APIs for the Java Platform. Many people think of the new capabilities as just offering non-blocking I/O operations. However, the new features introduced into the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4 Beta, include many other new and interesting features. While the API certainly will offer support for scalable I/O operations for both sockets and files, you'll also find a regular expression package for pattern matching, encoders and decoders for character set conversions, and improved file system support like file locking and memory mapping. All four of these new features will be covered in this article.

The MegaJogos site, headed by Marcos Fonseca, is a successful multi-user game site, with a number of multi-player games available. Our interest in this site is not in the Portuguese language (it is a Brazilian site), nor even in the games; instead, we were interested in this site because the games are implemented in the Java language, and these games were experiencing performance problems. The problem was not an animation problem, or any of the performance problems you typically might expect with games, but instead a low-level scalability issue.

One of the reasons I decided to develop XI now was to experiment with the new regular expression (regex) engine that's built into JDK 1.4. As you will see, I got more than I bargained for when I launched into an exploration of the New I/O package (commonly referred to as NIO, it's in package java.nio).

The new input/output (NIO) library, introduced with JDK 1.4, provides high-speed, block-oriented I/O in standard Java? code. This hands-on tutorial covers the NIO library in great detail, from the high-level concepts to under-the-hood programming detail. You'll learn about crucial I/O elements like buffers and channels, and examine how standard I/O works in the updated library.

Future articles will discuss channels and other new I/O features introduced in Java version 1.4.0. Those discussions will depend heavily on an understanding of the Buffer class and its subclasses, including ByteBuffer.

Future lessons will walk you through sample programs that use FileChannel objects to perform read/write file IO for different primitive data types as well as for data records containing mixed primitive data types.

This lesson will walk you through a sample program that uses FileChannel objects in conjunction with ByteBuffer objects to perform read/write file IO for data of the primitive type byte.

The recently released JavaTM 2 SDK, Standard Edition Version 1.4 contains a large number of new features, including the concept of IO channels. The first lesson in this miniseries, entitled FileChannel Objects in Java, Background Information, introduced you to the concept of channels from a read/write IO viewpoint. The previous lesson, entitled FileChannel Objects in Java, ByteBuffer Type, showed you the basics of read/write programming using channels.

This program, which was tested using Java SDK version 1.4.0 under Win2000, illustrates the use of FileChannel objects to write, read, and manipulate records containing data of mixed primitive types.

w___w_w_.___j_av__a__2s__._c___o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.