Home » Tag Archives: file

Tag Archives: file

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 »

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 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 »

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 »

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 »

Change File Last Modified date in Java example

In this example we are going to see how you can change the “Last Modified” date of a File in your File System in Java. We are simply going to use the setLastModified method of the File class. We are also going to see how you can parse a string with a date format to a Date object which is ...

Read More »

Move Files in Java example

In this example we are going to see how you can move a file to a new location in your File Path. In Java, there is no generic function you can use to do that. Nevertheless, you can use two ways to perform this operation: Use the renameTo function of the File class to do it. Copy the the File ...

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 »