Home » Tag Archives: io

Tag Archives: io

Java ImageIO – Write image to file

This is an example of how to write an image to a file, making use of the ImageIO utility class of Java. ImageIO class of javax.imageio package, provides methods to locate ImageReaders and ImageWriters, to perform encoding and decoding and other methods for image processing. Among the methods of ImageIO class, there are the write(RenderedImage im, String formatName, File output), ...

Read More »

Java RandomAccessFile Example

In this tutorial we are going to see how use RandomAccessFile in order to to read an write data to a File in random positions. The RandomAccessFile class treats the file as an array of Bytes. And you can write your data in any position of the Array. To do that, it uses a pointer that holds the current position (you ...

Read More »

Copy binary file with streams

With this example we are going to demonstrate how to copy a binary file using the FileInputStream and the FileOutputStream. In short, to copy a binary file with streams you should: Create a new FileInputStream, by opening a connection to an actual file, the file named by the path source name in the file system. Create a new FileOutputStream to ...

Read More »

Read char from console with InputStream

This is an example of how to read a char from console using an InputStream. It is an abstract class that is the superclass of all classes representing an input stream of bytes. Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input. Reading a char implies that you ...

Read More »

Read line of chars from console with InputStream

In this example we shall show you how to read a line of chars from console with an InputStream. This abstract class is the superclass of all classes representing an input stream of bytes. Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input. To read a line of ...

Read More »

Write byte array to file with FileOutputStream

With this example we are going to demonstrate how to write a byte array to a file using a FileOutputStream. The FileOutputStream is an output stream for writing data to a File or to a FileDescriptor. In short, to write a byte array to a file using a FileOutputStream you should: Create a new File instance by converting the given ...

Read More »

Append output to file with FileOutputStream

This is an example of how to append output to a file using the FileOutputStream. The FileOutputStream is an output stream for writing data to a File or to a FileDescriptor. Appending output to a file implies that you should: Create a new File instance by converting the given pathname string into an abstract pathname. Create a new FileOutputStream to ...

Read More »

Tokenizer from FileReader example

In this example we shall show you how to get a tokenizer from a FileReader. The FileReader is a convenience class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate. To get a tokenizer from a FileReader one should perform the following steps: Create a new FileReader, ...

Read More »

Read file with FileInputStream

With this example we are going to demonstrate how to read a File with a FileInputStream. The FileInputStream obtains input bytes from a file in a file system. In short, to read a File with a FileInputStream you should: Create a new File instance by converting the given pathname string into an abstract pathname. Create a FileInputStream by opening a ...

Read More »

Read file in byte array with FileInputStream

This is an example of how to read a File in a byte array using a FileInputStream. The FileInputStream obtains input bytes from a file in a file system. Reading a file in a byte array with a FileInputStream implies that you should: Create a new File instance by converting the given pathname string into an abstract pathname. Create a ...

Read More »