If you are working with the File APIs in Java, it is common that you would encounter the FileNotFoundException. This is a subclass of IOException. This Java exception is thrown by the classes FileInputStream, FileOutputStream, and RandomAccessFile. These classes trying to access a file in the system for the purposes of reading or writing into …
Java File IO
How To Write Properties To XML File In Java
In my previous tutorial I have written a sample program to write properties to a properties file. This example is writing the properties object values to a XML file. Here we are using the storeToXML method instead of just store method. This method will create the XML file with the content in the properties object. Lets look at …
How To Get Free Disk Space In Java (Windows)
This simple Java program helps you to get the free disk space on your windows machines. Here I have used three methods for getting the disk space from your system. getTotalSpace() getUsableSpace() getFreeSpace() The above methods are introduced from Java 6.0 and as part of the java.io package. The below example prints the disk space …
How To Get OS In Java
This post writes a simple Java example program to get the current operating system. There is a system property in Java, System.getProperty(“os.name”) which returns the operating system. However, this utility returns the operating system type like Windows, Mac, Unix or Linux. Lets look at the below example. GetOSExample.java Output…
File Modified Date Manipulation in Java
This example demonstrates the basic data manipulation operation in a File object. Java File object has set of methods to perform the following operations: Get the file last modified date Change the file modified date Lets look at the example to see how the above operations are implemented in Java example program. We use SImpleDateFormat …
How To Set The File Permissions In Java
Setting the file permissions in Java is OS specific. Each type of file system have different kind of file systems. Java provides the very generic solution to set the file permissions for all kind of file systems. This example demonstrates how to set file permissions to a file in the Linux operating system using Java …
Read An Object From File In Java (Deserialization)
In my previous tutorial I have explained about writing an object to a file using the serialization concept. Once you have written to a file, that file will be transferred across the network and would reach the destination. Once it is received, the receiver has to decode that file abd reading and converting back to …
Write An Object To File In Java (Serialization)
Java objects can be written to a file. If you implement Serializable interface to a class, implicitly that class is eligible for the serialization. Serializable is a marker interface which doesn’t have any methods defined. Serialization is the concept where an object can be converted to byte streams and transferred to the network. It is very much useful …