This tutorial will help you to identify that file is a file or directory? java.io.File class provides two methods .isFile() and .isDirectory () with the help these two methods you find out if the file is file or a directory.
This file utility method helps you to remove the file extension from file name. Here I am using simple regular expression which will remove the last dot followed by one or more characters of file extension.
This Java File API boolean java.io.File.renameTo(File newFile) method is used to rename the file. It is always recommended to check the return value. It helps you to make sure that the rename operation was successful or not. API It returns true when rename is successful, and false if unsuccessful.
Some times in application development, we required to delete files older than specified number of days. Actually this is clean up utility which removes older files from disk and free the hard disk memory.
Recently I am working on the some java file operation task,Requirement is so simple , program should reads all the files and folders. There are thousands of files generated on hard drive on daily basis so my program need to delete all those files whose file-size is more than 10MB.This clean up executed on daily basis and delete the respected files.
In this tutorial we will learn how append content to file in Java. It will constructs a FileWriter object on given a File object. If the second argument is true then bytes will be written to the end of the file rather than the beginning.
Its good programming practice to perform check, whether the file is exists or not before performing any file IO operation. Below Java code used to determine the file or folder is exists or not on your hard drive.
In this tutorial we will learn how to get current file path In Java.Refer below code to display the current directory path. There are two way to get the current directory path either get it through new File(".").getCanonicalPath() method. Here dot represents the current directory. And another way is using user.dir property. System.getProperty("user.dir").