How to use a FileChannel to read data into a Buffer in java code?

Below Java code shows how to use FileChannel to read data into buffer. This is done by following below steps : Create FileInputStream for the file to be read Create FileChannel from FileInputStream Create ByteBuffer as channel reads data into buffer and set the limit of ByteBuffer. Read data from channel to byteBuffer To read …

Read More

How to filter specific type of Files using FileFilter class in java?

Below java code show how to filter specific type of files using FileFilter class – To implement the FileFilter interface we need to create an accept() method which takes a java.io.File object as parameter. In the method we check wheter the name ends with “.txt” and if so we return true, else false. When we …

Read More

How to change an applet background color?

Applet’s default background color is Grey. If you want to change it then you need to call the setBackground(java.awt.Color) and choose the color you want. Defining the background color in the init method will change the color as soon as the applet initialized.

Read More

How to Write/Store an object to file in java?

Writing a Java objects to a file is called as Serialization in java. In order to do this, you have to implement the Serializable interface, and use ObjectOutputStream to write the object into a file. To do this we have created Employee class which implements java.io.Serializable. To write an object to a stream call the …

Read More