Java.io - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Java.io Interfaces

Java.io Interfaces

shape Introduction

Java.io Interfaces - The data steaming, serialization and the file system for a system is provided by java.io.Interfaces.

Interfaces

shape Table

Java.io Interfaces Description
FileFilter Abstract pathnames can be known using this interface.
FilenameFilter This interface is used to filter the filenames of a particular class.
Data Input Used to reconstruct the data and read the bytes from the binary stream in a java primitive types.
Data Output This interface used to convert the data of a java primitive type to a series of bytes and write to a binary stream.
Closeable The destination or source of a data can be closed using this interface.
Externalizable This interface used to identify a class of Externalizable instance and responsible for saving and restoring contents of a class, which are written in the serialization stream.
Flushable The data can be flushed using this interface.
Object Input Using this interface the data input can be extended and the objects can be read.
Object Output This interface used to extend the data output interface, which include writing of objects.
ObjectInputValidation This interface is used to callback and allow the validations of object in a graph.
ObjectStreamConstants By using this interface the constants can be written into the object serialization stream.
Serializable By implementing the java.io.Serializable interface, this interface enables.

shape Example

Java.io Interfaces - The following is an example. [java] package com.cp.io; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; public class DataInputStreamDemo { public static void main(String[] args) throws IOException { InputStream is = null; DataInputStream dis = null; try{ // create input stream from file input stream is = new FileInputStream("E:\\splesson.txt"); // create data input stream dis = new DataInputStream(is); // count the available bytes form the input stream int count = is.available(); // create buffer byte[] bs = new byte[count]; // read data into buffer dis.read(bs); // for each byte in the buffer for (byte b:bs) { // convert byte into character char c = (char)b; // print the character System.out.print(c+" "); } }catch(Exception e){ // if any I/O error occurs e.printStackTrace(); }finally{ // releases any associated system files with this stream if(is!=null) is.close(); if(dis!=null) dis.close(); } } } [/java] Output The following is the result. [java]H e l l o J a v a . J a v a I O i s f u n . [/java]

Summary

shape Key Points

  • Java.io Interfaces - The data steaming, serialization and the file system for a system is provided by java.io.Interfaces.