Home » Core Java » io » FileOutputStream

FileOutputStream

java.io.FileOutputStream Example

In this example we are going to talk about FileOutputStream. FileOutputStream is a subclass of OutputStream, which is used to transfer data from your program to a resource. And in this case to a file that resides in your underlying file system. OK, so let’s start with some simple examples.             1. Writing bytes to ...

Read More »

How to copy a directory in Java

In this tutorial we are going to see how you can copy a directory in Java. The idea is very simple. You open the directory and you list the contents. Then you open the contents and examine them one by one. If the entry you are looking at is a File, you can copy it to the new location. If ...

Read More »

Decompress a GZIP File in Java example

In the previous tutorial we saw how to compress a File with the GZIP method. In this tutorial we are going to see how to decompress the File that was compressed with the GZIP method. Basically all you have to do to decompress a gzipped file is: Create a FileInputStream to the compressed File. Create a GZIPInputStream to the above ...

Read More »

Compress a File in GZIP format in Java

In this tutorial we are going to see how you can compress a File in Java using the GZIP compression method. So, to perform File compression using GZIP in Java, you have to: Create a FileOutputStream to the destination file, that is the file path to the output compressed file. Create a GZIPOutputStream to the above FileOutputStream. Create a FileInputStream ...

Read More »

How to Write an Object to File in Java

On this tutorial we are going to see how you can store an object to a File in your File system in Java. Basically to perform basic IO operations on object, the class of the object has to implement the Serializable interface. This gives the basic interface to work with IO mechanisms in Java. In short, in order to write ...

Read More »

4 Ways to Copy File in Java

Although Java offers a class that can handle file operations, that is java.io.File, it doesn’t have a copy method that will copy a file to another. The copying action is an important one, when your program has to handle many file related activities. Nevertheless, there are several ways you can perform a file copying operation in Java and we will ...

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 »