Package Zuoye;import java.io.filereader;import java.io.filewriter;import java.io.IOException; Public classTEXTRW { Public Static voidMain (string[] args) {//writing a textrw file Try{FileWriter FW=NewFileWriter ("D:/zuoye1.txt"); Fw.write ("My name is: Kang, school Number: 0816"); Fw.close (); System. out. println ("Write Success"); FileReader FR=NewFileReader ("D:/zuoye1.txt"); Char[]nb=New Char[1024x768]; intI=0; StringBuilder SB=NewStringBuilder (); while((I=fr.read (NB)) >0) {sb.append (NB,0, i); } fr.close (); System. out. println ("Read ="+SB); System. out. println ("Read Success! "); } Catch(IOException e) {//TODO Auto-generated catch blockE.printstacktrace (); } }}
Writing Textrw.java Java applications, the function of the program is to first write its own number and name to TextRw.txt, read the information in TextRw.txt and display it on the screen.