Home » Core Java » io (page 2)

io

Java ByteArrayInputStream Example

In this example we will discuss about ByteArrayInputStream class and its usage. A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream. An internal counter keeps track of the next byte to be supplied by the read method. ByteArrayInputStream extends InputStream, the abstract class which is the superclass of all classes representing an input ...

Read More »

Java BufferedInputStream Example

In this example we will discuss about BufferedInputStream class and its usage. The BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods. BufferedInputStream extends FilterInputStream, which simply overrides all methods of InputStream with versions that pass all requests to the contained input stream. The BufferedInputStream class exists since ...

Read More »

Java BufferedOutputStream Example

In this example we will discuss about BufferedOutputStream class and its usage. The class implements a buffered output stream. By setting up such an output stream, an application can write bytes to the underlying output stream without necessarily causing a call to the underlying system for each byte written. BufferedOutputStream extends FilterOutputStream, which is the superclass of all classes that ...

Read More »

Java BufferedWriter Example

In this example we will discuss about the BufferedWriter class and its usage. BufferedWriter writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. BufferedWriter extends Writer, which is an abstract class for writing to character streams. The only methods that a subclass must implement are write(char[], int, ...

Read More »

Java FileWriter Example

Last updated Jan. 21, 2019 In this example we will discuss about the FileWriter class and how to use it to write streams of characters. Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileWriter (or other file-writing ...

Read More »

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 »

Delete File in Java Example

In this example we are going to see how to delete a file in Java. Of course Java offers a very convenient API to perform deletion and creation. Most of them are placed in File class. We are going to use delete() methods that deletes the file or directory. If the file is deleted successfully, the methods returns true, else ...

Read More »

java.io.IOException – How to solve IOException

In this example we are going to talk about a very common exception that many java developers stumble upon when dealing with IO operations in their program : IOException. This exception occurs when an IO operation has failed for some reason. It is also a checked exception which means that your program has to handle it. All bult-in Java IO ...

Read More »

How to Create Directory in Java Example

Following the “How to create file in Java Example“, in this example we are going to see how to create a new Directory/Folder in your file system with Java. As you might have noticed, Java offers a very rich I/O API. So. it is fairly easy to create a Directory in Java. 1. Create a single Directory Let’s see how ...

Read More »

How to create file in Java Example

In this example we are going to see how to create a new file in Java. It’s fairly easy to do so, using Java File class. First of all, you have to format a string that describes the file path in your file system that you want to create this file into. For this example, I’ve worked on a Windows ...

Read More »