Home » fileoutputstream

Tag Archives: fileoutputstream

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 »

java.io.OutputStream Example

In this example we are going to talk about OutputStream class in Java. OutputStream is an abstract class that enables you to write data to an output sink or destination. As with InputStream, that destination could be a console, a file, a socket, a pipe and even a buffer in memory. The most basic and fundamental thing you can do ...

Read More »

Java write to File Example

In this post, we feature a comprehensive example of how to write to File in Java using FileWriter, FileOutputStream, and NIO. We are going to investigate several methods to write a File in Java. We will list some of the older, before Java 7 and NIO, methods to write to a text or a binary file as well as some ...

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 »

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 »