Home » Core Java » io (page 4)

io

Java StringWriter Example

In this example we are going to see how to use StringWriter. StringWriter is a subclass of java.io.Writer and can be used to write character streams in a String buffer and later can be used to obtain the stream as a String and even obtain the output buffer as a StringBuffer. Let’s see some examples.           ...

Read More »

Java PrintWriter Example

Java provides us PrintWriter class, from which we can print formatted and human readable data in a stream. The text-output stream can be either OutputStream or Writer. More specifically it doesn’t contain methods for printing the primitive types (for instance int, long etc) as byte values, but as text-format representation. In this example, we are going to print some common ...

Read More »

Get the filepath of a File in Java

In this tutorial we are going to see how to get the absolute file path as well as the path of the parent directory of a specific file. This is very useful because it gives a generic way to get the absolute paths of files, independently of the operating system you use. Additionally, among many other uses cases, if you’ve ...

Read More »

How to get the standard input in Java

In this tutorial we are going to see how to use the standard input in Java. As you can imagine this is probably one of the most basic things you have to learn when you start up with programming, because it really is fundamental to read user input and process it as you want. Basically, all you have to do ...

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 Read an Object from File in Java

In the previous tutorial we saw how to write an Object to a file in Java. In this example we are going to see how to read an Object from the file that we’ve stored it earlier. Basically, to read an Object from a file, one should follow these steps: Open a FileInputStream to the file that you’ve stored the ...

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 »

Get free disk space in Java example

With this tutorial we are going to see how to use the File class in order to get the size of certain disk partitions in your file system. You can use: getTotalSpace() to get the total capacity of the disk partition you want. getFreeSpace() to get the free space of the disk partition. getUsableSpace() to get the usable space in ...

Read More »