character Streams
"Write data to a file"
Now we use character streams
/** * character streams * write data  * */&N
Bsp import java.io.*; class hello{ public static void main (String[]& Nbsp;args) throws ioexception { string&nbs P;filename= "D:" +file.separator+ "Hello.txt"; file f=new file (fileName); writer out =new filewriter (f); string str= "Hello"; out.write (str); out.close ();
} }
When you open hello. TXT, you'll see hello.
In fact, the previous example in this example makes no difference, but you can simply type the string without having to convert the string into a byte array.
When you want to ask for additional content in the file, you can use the same line as the one above to:
Writer out =new FileWriter (f,true);
This way, when you run the program, you find that the contents of the file become:
Hellohello If you want to change lines in a file, you need to use "\ r \ n"
For example, change str to string str= "\r\nhello";
The contents of the STR that are appended to the file are then wrapped.
Read from the file:
/** & nbsp;* character streams * read content from files * */ import java.io.* ; class hello{ public static void main (String[]& Nbsp;args) throws ioexception { string&nbs P;filename= "D:" +file.separator+ "Hello.txt"; file f=new file (fileName); char[] ch=new char[100];