Types of language components

Source: Internet
Author: User
Tags readline

The variety of languages varies widely. However, generally speaking, there are 4 basic ingredients.

Data components. Used to describe the data involved in the program.

Operational components. Used to describe the operations contained in the program.

Control ingredients. Used to express control constructs in the program.

Transport components. Used to express the transmission of data in a program

1  Packagecom.tabletest;2 ImportJava.io.BufferedReader;3 ImportJava.io.BufferedWriter;4 ImportJava.io.FileReader;5 ImportJava.io.FileWriter;6 Importjava.io.IOException;7 ImportJava.text.SimpleDateFormat;8 Importjava.util.Date;9 Ten  One  A  Public classtabletext_25 - { -          Public Static voidMain (string[] args) the         { -SYSTEM.OUT.PRINTLN ("Success"); - writeMethod1 (); - writeMethod2 (); + writeMethod3 (); - readMethod1 (); + readMethod2 (); A         } at         /** - * Write text files using the FileWriter class -          */ -          Public Static voidwriteMethod1 () -         { -String filename= "H://borter.txt"; in                 Try -                 { to                         //when using this constructor, if a borter.txt file exists, +                         //Delete the file first, and then create a new Borter.txt -FileWriter writer=NewFileWriter (fileName); theWriter.write ("Hello borter:\n"); *Writer.write ("My name is borter!\n"); $Writer.write ("I like you and miss. ");Panax Notoginseng writer.close (); -}Catch(IOException e) the                 { + e.printstacktrace (); A                 } the         } +         /** - * Use the FileWriter class to append information to a text file $          */ $          Public Static voidwriteMethod2 () -         { -String filename= "H://borter.txt"; the                 Try -                 {Wuyi                         //when using this constructor, if a borter.txt file exists, the                         //append the string directly to the Borter.txt -FileWriter writer=NewFileWriter (FileName,true); WuSimpleDateFormat format=NewSimpleDateFormat (); -String Time=format.format (NewDate ()); AboutWriter.write ("\n\t" +Time ); $ writer.close (); -}Catch(IOException e) -                 { - e.printstacktrace (); A                 } +         } the         //Note: The above example is only possible with the FileWrite class because there is very little text written. But if you need to write the -         //a lot of content, you should use a more efficient buffer flow class bufferedwriter.  $         /** the * Write text files using the BufferedWriter class the          */ the          Public Static voidwriteMethod3 () the         { -String filename= "H://borter.txt"; in                 Try the                 { theBufferedWriter out=NewBufferedWriter (NewFileWriter (FileName)); AboutOut.write ("Hello Tom:"); theOut.newline ();//Note that the line-wrapping effect does not always occur on various computers . theOut.write ("My name is tom!\n"); theOut.write ("I like you and miss. "); + out.close (); -}Catch(IOException e) the                 {Bayi                         //TODO auto-generated Catch block the e.printstacktrace (); the                 } -         } -         /** the * Use FileReader class to read text files the          */ the          Public Static voidreadMethod1 () the         { -String filename= "H://borter.txt"; the                 intC=0; the                 Try the                 {94FileReader reader=NewFileReader (fileName); theC=Reader.read (); the                          while(C!=-1) the                         {98System.out.print ((Char) c); AboutC=Reader.read (); -                         }101 reader.close ();102}Catch(Exception e) {103 e.printstacktrace ();104                 } the         }106         107         /**108 * Use BufferedReader class to read text files109          */ the          Public Static voidreadMethod2 ()111         { theString filename= "H://borter.txt";113String line= ""; the                 Try the                 { theBufferedReader in=NewBufferedReader (NewFileReader (FileName));117Line=in.readline ();118                          while(line!=NULL)119                         { - System.out.println (line);121Line=in.readline ();122                         }123 in.close ();124}Catch(IOException e) the                 {126 e.printstacktrace ();127                 } -         }129}

Types of language components

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.