Java – List of available MessageDigest Algorithms
In Java, you can use the Security.getAlgorithms("MessageDigest") to list all the available MessageDigest algorithms.
Java – Create file checksum with SHA and MD5
In this article, we will show you how to use a SHA-256 and MD5 algorithm to generate a checksum for a file. We have 2 ways: (1) using MessageDigest.getInstance(“algorithm”), (2)…
How to assign file content into a variable in Java
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…
How to check if a file is hidden in Java
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…
How to check if a file exists in Java
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…
Java – Count number of lines in a file
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…
How to get file size in Java
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).…
How to make a file read only in Java
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…
How to get file creation date in Java
In Java (@since 1.7), we can use the NIO Files.readAttributes to get all the file metadata, including the file creation date. We also can use the same code to get…