Home » Core Java » io

io

Java 7 New IO API Example

1. Introduction Java NIO (New IO) is an alternative IO API for Java (from Java 1.4) – it was deemed to be the alternative standard to the Java IO and Java Networking API. Of course, there wouldn’t be a new one if it’s not for the benefits of using it. It does still has the basic file manipulation capabilities but ...

Read More »

java.io.Console: New Feature in Java 6

System.console() method is used for getting a unique instance of the Class Java.io.Console. Console device is associated with current Java virtual machine running. It is assumed that underlying platform is started from interactive command line. If the virtual machine is started automatically by a background job or a service, it would not have a console. The methods on Console are ...

Read More »

java.io.Externalizable Example

In this tutorial we will discuss about the Externalizable interface in Java. The Externalizable interface provides a way to implement a custom serialization mechanism. A class that implements the Externalizable interface is responsible to save and restore the contents of its own instances. Furthermore, the Externalizable interface extends the Serializable interface and provides two methods to serialize and de-serialize an ...

Read More »

Java StringReader Example

In this tutorial we will discuss about the StringReader in Java. The StringReader class represents those character streams, whose source is a string. The StringReader class extends the Reader class, which is an abstract class for reading data from character streams. The sub-classes of the Reader class must implement the following two methods: read(char[], int, int) close() Finally, the StringReader ...

Read More »

Java ObjectInputStream and ObjectOutputStream Example

In this example we will see how we can use Java’s ObjectInputStream and ObjectOutputStream classes to serialize objects and store them as a file or any other storage accessible by Output Stream; read them again, deserialize it into an object and use it. ObjectOutputStream Example So, first we will see how to write an object into a File using FileOutputStream ...

Read More »

Java File Filter Example

Usually there is a need of filtering files into our app and/or show only specific type of files to the users. So, we can limit the appearance of the files with the use of FilenameFilter interface. This could be useful when we have to deal with large file systems or facilitate the user to select a file. In this example ...

Read More »

Java File Descriptor Example

In this post we will discuss Java FileDescriptor class and its use case. Before we see an example, first lets try to understand what is File Descriptor and why it is used. Whenever a file is opened, the operating system creates an entry to represent this file and stores its information. Each entry is represented by an integer value and ...

Read More »

Java StreamTokenizer Example

In this example we will see how to use Java StreamTokenizer class to parse an input stream into tokens. We can use this class to break the InputStream object or an object of type Reader into tokens based on different identifiers, numbers, quoted strings, and various comment styles. The use of InputStream as the input parameter is deprecated, so we ...

Read More »

java.io.tmpdir Example

In this tutorial we will discuss about the java.io.tmpdir system property. The java.io.tmpdir system property indicates the temporary directory used by the Java Virtual Machine (JVM) to create and store temporary files. The default value is typically "/tmp", or "/var/tmp" on Unix-like platforms. On Microsoft Windows systems the java.io.tmpdir property is typically "C:\\WINNT\\TEMP". During your application’s execution, you can acquire ...

Read More »

Java ByteArrayOutputStream Example

In this example we will discuss about ByteArrayOutputStream class and its usage. This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is written to it. The data can be retrieved using toByteArray() and toString(). ByteArrayOutputStream extends OutputStream, the abstract class which is the superclass of all classes ...

Read More »