Automatic resource Management (ARM) is introduced in Java7, and resources in try () {}catch{}finally{}, () are freed automatically after the program runs.
File stream is divided into input stream and output stream, typical usage
FileReader FR = new FileReader ("Poem.txt"); Read an existing file
FileWriter FW = new FileWriter ("NewPoem2.txt");//write to a specific name file (no first created), overwrite
char[] Cbuf = new CHAR[32]; Reader and writer Read and write in character units
int hasread = 0; Returns the number of reads at one time
while ((Hasread = Fr.read (cbuf)) > 0)
{
Fw.write (Cbuf,0,hasread);
}
FileInputStream fis = new FileInputStream ("Poem.txt");
FileOutputStream fos = new FileOutputStream ("NewPoem.txt"))
byte[] Bbuf = new BYTE[32]; InputStream and OutputStream read-write in bytes
int hasread = 0;
while ((Hasread = Fis.read (bbuf)) > 0)
{
Fos.write (Bbuf,0,hasread);
}
Java IO operations