The java.io package contains all the classes required for input and output operations.
IMPORTANT TERMS
Input Output Redirection : I/O stream ends change direction and placed on file , console, or printer whenever required.
Stream : Its the flow of data
Input Stream : Input Stream is used for many things that you read from in the form of stream of bytes.
Output Stream : Output Stream is used for many things that you write to in the form of stream of bytes.
Reader : Similar to Input Stream but data read character by character.
Writer : Similar to Output Stream but data read character by character.
BufferedReader : This class reads text from a character-input stream, buffering characters so as to provide for the efficient reading.
FILE OPERATIONS
File(String pathname) : creates a new File instance by converting pathname string into an abstract pathname. eg.
File file=new File("C:/prog/AnyName.txt");
getName() : returns the name of the file or directory. eg.
String name = file.getName();
getAbsolutePath() : returns the absolute pathname string. eg.
String path = file.getAbsolutePath();
exists() : checks whether the file or directory exists or not. eg.
if(file.exists()){
//do the coding here
}
isDirectory() : tests whether the file is a directory. eg.
if(file.exists()){
if(file.isDirectory()){
System.out.println(file.getName()+" is a directory..");
}
}
lastModified() : returns the time when the file was last modified. eg.
long time = file.lastModified();
mkdir() : creates single directory. eg.
file = new File("C:/Java");
// creates directory
bool = file.mkdir();
mkdirs() : creates recursive directories. eg.
file = new File("C:/Folder1/Folder2/Java");
// create directories
bool = file.mkdirs();