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.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.