Java – How to save byte[] to a file
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…
Favourite tutorials for developers
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…
In Java, you can use the Security.getAlgorithms("MessageDigest") to list all the available MessageDigest algorithms.
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)…
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…