/*
Character Stream:
Reader Writer.
Demand:
Create a file on your hard disk and write some data.
*/
Importjava.io.*;
/*
Creates a FileWriter object, invokes a window resource, and creates a destination for data storage at the specified location.
If the file you want to create already exists under the specified directory, it will be overwritten.
FileWriter FW = new FileWriter ("Demo.txt");
Writes a string to the stream through the stream object write method.
Fw.write ("ABCDE");
Close the resource and clear it first.
Fw.close ();
Requirements: The original file for the continuation of the data write.
1, set the object.
2, use the read-write method.
3, close the resource.
*/
classFilewriterdemo
{
Public
Static
voidMain (string[] args)//throws IOException
{
FileWriter FW=Null
Try
{
Fw=
NewFileWriter ("K:\\demo.txt", true);
Fw.write ("Qqqqq\r\nmmmm");
}
Catch(IOException e)
{
System.out.println (E.tostring ());
}
finally
{
if(FW!=Null
Try
{
Fw.close ();
}
Catch(IOException e)
{
System.out.println ("Close:"+E.tostring ());
}
}
}
}
Package Model;import Java.io.filenotfoundexception;import Java.io.filereader;import java.io.ioexception;public Class Filereaddemo {public static void main (string[] args) {try {FileReader fr = new FileReader ("E:\\demo.txt"); char[] Arr = new Char[1024];int num = 0; try {while (num = Fr.read (arr))!=-1) { System.out.println (new String (Arr,0,num));} } catch (IOException E {//TODO auto-generated catch Blocke.printstacktrace ();}} catch (FileNotFoundException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}
Java Read and write function