1. Write Textrw.java java application, the function of the program is: first write their own number and name to TextRw.txt, read the information in TextRw.txt and display it on the screen.
PackageTest03;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classTEXTRW { Public Static voidMain (string[] args) {File file=NewFile ("D:/textrw.txt"); Try{FileOutputStream out=Newfileoutputstream (file); String nr= "Study No.: 123456, Name: Zhang Shuai"; byte[] b=nr.getbytes (); System.out.println ("Write succeeded"); Out.write (b); Out.close (); //close the stream and release the resource//input stream read into memory from file bar dataFileInputStream in =Newfileinputstream (file); //array loaded in the data byte[] b1=New byte[1024]; intI=0; String Str=""; while((i = In.read (B1)) >0) { //Combining Data//parameter 1-start positionstr + =NewString (b1,0, i); } System.out.println (str); } Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); } }}
Java fundamentals-Input and output: 1. Write Textrw.java java application, the function of the program is: first write their own number and name to TextRw.txt, read the information in TextRw.txt and display it on the screen.