Coders Packet

Creating New Files and Directories in Java File and Stream

By Rakesh Jat

file systems, reading from files, or writing to files, from java.io: System Class Input and Output

The File class can be used to create files and directories. A file can be created whose
pathname is specified in a File object using the following method:
A directory whose pathname is specified in a File object can be created using the
following methods:
String[] list()
String[] list(FilenameFilter filter)
File[] listFiles()
File[] listFiles(FilenameFilter filter)
File[] listFiles(FileFilter filter)
The filter argument can be used to specify a filter that determines whether an
entry should be included in the list. These methods return null if the abstract
pathname does not denote a directory, or if an I/O error occurs. A filter is an
object of a class that implements either of these two interfaces:
interface FilenameFilter {
boolean accept(File currentDirectory, String entryName);
}
interface FileFilter {
boolean accept(File pathname);
}
The list() methods call the accept() methods of the filter for each entry to
determine whether the entry should be included in the list.
boolean createNewFile() throws IOException
It creates a new, empty file named by the abstract pathname if, and only if, a
file with this name does not already exist. The returned value is true if the file
was successfully created, false if the file already exists. Any I/O error results
in an IOException.
boolean mkdir()
boolean mkdirs()
The mkdirs() method creates any intervening parent directories in the
pathname of the directory to be created..

//how to delete file in full project

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Rakesh Jat (techraka)

Download packets of source code on Coders Packet