Java input and output basic operations example

Source: Internet
Author: User

The inheritance of these classes is somewhat similar, take one as a sample, and understand the mechanism.

 PackageCc.openhome;ImportJava.io.*; Public classMember {PrivateString number; PrivateString name; Private intAge ;  PublicMember (string number, string name,intAge ) {         This. Number =Number ;  This. Name =name;  This. Age =Age ; } @Override PublicString toString () {returnString.Format ("(%s,%s,%d)", number, name, age); }         Public voidSave () {Try{dataoutputstream Output=NewDataOutputStream (NewFileOutputStream (number));            Output.writeutf (number);            OUTPUT.WRITEUTF (name);        Output.writeint (age); } Catch(IOException ex) {Throw NewRuntimeException (ex); }    }         Public StaticMember Load (String number) {Member Member=NULL; Try{DataInputStream input=NewDataInputStream (NewFileInputStream (number)); Member=NewMember (Input.readutf (), Input.readutf (), Input.readint ()); } Catch(IOException ex) {Throw NewRuntimeException (ex); }        returnmember; }}
 Package Cc.openhome; import java.io.*;  Public class Memberdemo {    publicstaticvoid  main (string[] args) {         New Member ("B1234", "justing", "a"),new Member ("B4532", "Monica", and All)};          for (Member member:members) {            member.save ();        }        System.out.println (Member.load ("B1234"));}    }

Sample input and output basic operations for Java

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.