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.
Packagecom. IO;ImportJava.io.*; Public classTESTRW { Public Static voidMain (string[] args) {Try{File File=NewFile ("D:/textrw.txt"); if(!file.exists ()) {File.createnewfile (); } FileWriter FW=NewFileWriter (file); Fw.write ("School Number: 013\n name: Zhao Four"); Fw.close (); FileReader FR=Newfilereader (file); Char[]c=New Char[1024]; String Str=""; intI=0; while((I=fr.read (c)) >0) {str+=NewString (c,0, i); } fr.close (); System.out.println (str); } Catch(Exception e) {e.printstacktrace (); } }}
writing Iodemo.java Java applications, the function of the program is to read the text first . txt The file content, and then through the keyboard input file name is Iodemo.txt, the text . txt the content is deposited iodemo.txt
Packagecom. IO;ImportJava.io.*; Public classIodemo { Public Static voidMain (string[] args) {Try{File File=NewFile ("D:/text.txt"); FileReader FR=Newfilereader (file); String Str=""; Char[]c=New Char[1024]; intI=0; while((I=fr.read (c)) >0) {str+=NewString (c,0, i); } fr.close (); System.out.println (str); File file1=NewFile ("D:/iodemo.txt"); if(!file1.exists ()) {File1.createnewfile (); } FileWriter FW=NewFileWriter (FILE1); Fw.write (str); Fw.close (); } Catch(Exception e) {e.printstacktrace (); } }}
Write the Biniodemo.java Java application, the function of the program is to complete the 1.doc file copy, copy the name of the future file for their own school number name. doc.
Packagecom. IO;ImportJava.io.*; Public classBiniodemo { Public Static voidMain (string[] args) {Try{File File=NewFile ("D:/1.doc"); if(!file.exists ()) {File.createnewfile (); } FileWriter FW=NewFileWriter (file); Fw.write ("AAAA"); Fw.close (); FileReader FR=Newfilereader (file); intI=0; String Str=""; Char[]c=New Char[1024]; while((I=fr.read (c)) >0) {str+=NewString (c,0, i); } fr.close (); System.out.println (str); File file1=NewFile ("d:/013 Zhao four. doc"); if(!file1.exists ()) {File1.createnewfile (); } FileWriter FW1=NewFileWriter (FILE1); Fw1.write (str); Fw1.close (); } Catch(Exception e) {e.printstacktrace (); } }}
Java I/O exercises