Java – Convert File to Hex
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…
Favourite tutorials for developers
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…
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 use FileInputStream to read bytes from a file, such as an image file or binary file. The FileInputStream.read() reads a byte at a time, and it will…
Here is another example to show how to read a file in Java with BufferedInputStream and DataInputStream classes. The readLine() from the type DataInputStream is deprecated. Sun officially announced this…
In Java, file permissions are very OS specific: *nix , NTFS (windows) and FAT/FAT32, all have different kind of file permissions. Java comes with some generic file permission to deal…
In Java, there are many ways to create and write to a file: using Files.newBufferedWriter (Java 8), using Files.write (Java 7), using PrintWriter, using File.createNewFile