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…
Favourite tutorials for developers
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need to recompile.
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…
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…
This article shows how to do file transfer from a remote server to the local system and vice versa, using SSH File Transfer Protocol (SFTP) in Java. This Java example…
This article shows, in Java, how to move a file to another directory in the same file drive or remote server: (1) Files.move – Move file in local system, (2)…
In Java, we can use the NIO Files.move(source, target) to rename or move a file. The Apache FileUtils.moveFile uses a "copy and delete" mechanism to rename or move a file.…