Java FileReader Example

java-thumbnail

Java has several File IO classes for reading and writing into the files. Each class has its own advantages. This example illustrates how to use FileReader for reading a text file. The main purpose of using the FileReader is to read the text content from a file where FileInputStream is used for reading the stream of […]

FileNotFoundException in Java

java-thumbnail

If you are working with the File APIs in Java, it is common that you would encounter the FileNotFoundException. This 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 that file. Java doesn’t have the facility […]

How To Find A File In Classpath

java-thumbnail

This example program demonstrates how to find a file in the classpath. The simple approach is to get the classpath string using the System.getProperty() method which returns the complete string value of the classpath. Then you can split the values using the stringtokenizer and search eacy token against the file name. Lets look at the […]

How To Write Properties To XML File In Java

java-thumbnail

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 Write Properties File In Java

java-thumbnail

Properties files are stored values in the key-value pairs. This tutorial explains how you can create the properties file using the Java program. If you are aware, Java itself has a Properties class which is used for string the values in the key-value pairs. If you have the values in the Properties object, then those […]

How To Get Free Disk Space In Java (Windows)

java-thumbnail

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

java-thumbnail

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

java-thumbnail

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

java-thumbnail

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 […]

Convert InputStream To String In Java

java-thumbnail

In my previous example, I have written a simple program to covert string object to InputStream. This tutorial does the reverse, converting inputstream into a string object. Lets look at the example.