Java I/O exercises

Source: Internet
Author: User

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

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.