Java-File-Handling
Java-File-Handling
To use the File class, create an object of the class, and specify the filename or
directory name:
Creating a File :
----------------
import java.io.File;
import java.io.IOException;
Write a File:
------------
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
Delete a File:
--------------
String Buffer:
--------------
Java StringBuffer class is used to create mutable (modifiable) String objects. The
StringBuffer class in Java is the same as String class except it is mutable i.e. it
can be changed.
Constructor Description
StringBuffer() It creates an empty String buffer with the
initial capacity of 16.
StringBuffer(String str) It creates a String buffer with the specified
string..
StringBuffer(int capacity) It creates an empty String buffer with the specified
capacity as length.
The capacity() method of the StringBuffer class returns the current capacity of the
buffer. The default capacity of the buffer is 16. If the number of character
increases from its current capacity, it increases the capacity by
(oldcapacity*2)+2. For example if your current capacity is 16, it will be
(16*2)+2=34.
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
String Builder:
Java StringBuilder class is used to create mutable (modifiable) String. The Java
StringBuilder class is same as StringBuffer class except that it is non-
synchronized. It is available since JDK 1.5.