How to get free disk space in Java
In Java old days, it lacks of method to determine the free disk space on a partition. But this is changed since JDK 1.6 released, a few new methods –…
Favourite tutorials for developers
In Java old days, it lacks of method to determine the free disk space on a partition. But this is changed since JDK 1.6 released, a few new methods –…
This article shows how to convert a file into a hexadecimal (hex) representative format. The idea is to read the file into an InputStream and uses String.format(%X) to convert each…
This article shows a few ways to save a byte into a file. For JDK 1.7 and above, the NIO Files.write is the simplest solution to save byte to a…
In Java, we can use Files.readAllBytes(path) to convert a File object into a byte. Before Java 7, we can initiate a new byte with a predefined size (same with the…
Most people will read the file content and assign to StringBuffer or String line by line. Here’s another trick that may interest you – how to assign whole file content…
A Java program to demonstrate the use of java.io.File isHidden() to check if a file is hidden. The isHidden() method is system dependent, on UNIX platform, a file is considered…
In Java, we can use Files.exists(path) to test whether a file exists. The path can be a file or a directory. It is better to combine with !Files.isDirectory(path) to ensure…
This article shows few Java examples to get the total number of lines in a file. The steps are similar: (1) Open the file, (2) Read line by line, and…
In Java, we can use Files.size(path) to get the size of a file in bytes. This example uses NIO Files.size(path) to print the size of an image file (140 kb).…
A Java program to demonstrate the use of java.io.File setReadOnly() method to make a file read only. Since JDK 1.6, a new setWritable() method is provided to make a file…