Learn Java IO character stream from scratch lazy mode (automatic generation of attribute classes, method classes, interface classes)

Source: Internet
Author: User

usually do a project to build a lot of attribute class, method class and view class, after learning the IO stream to think of a way, is to write a string of code, and then write in the text document class < class name > plus all the attributes, Then run the code to automatically generate a < class name >.java file. Open it with a myeclipse. In the same way, you write a txt text document that has only class < class name > and another section of code that automatically generates a method class with a method class that includes additions and deletions to four simple methods, and a view class.

First of all, generate this code for the attribute class:

Package Com.jereh.generate;import Java.io.*;import java.util.*;p ublic class Generate1 {/** * @param args */public static V OID Main (string[] args) {FileReader FR = null; BufferedReader br = null; FileWriter FW = NULL;        BufferedWriter bw = Null;int i=0;        File File1 = new File ("e:\\io\\ original \\1.txt");        File file2 = null; try {stringbuffer sbff = new StringBuffer (); fr = new FileReader (file1); br = new BufferedReader (FR); String Next; while (!) ( (Next = Br.readline ()) ==null)) {if (i==0) {sbff.append ("public"); Sbff.append (next); Sbff.append ("{\ r \ n"); String[] A = Next.split (""); File2 = new File ("e:\\io\\ generated \ \" +a[1]+ ". Java");}    Else{sbff.append ("private"); Sbff.append (next+ "\ r \ n");} i++;} Sbff.append ("}"), FW = new FileWriter (file2), bw = new BufferedWriter (FW); Bw.write (sbff.tostring ());} catch (FileNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Au To-generated catch Blocke.printstacktrace ();} Finally{try {br.clOSE (); Bw.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}
then the code that generates the method class:

<span style= "FONT-SIZE:18PX;" >package com.jereh.generate;import java.io.bufferedreader;import Java.io.bufferedwriter;import java.io.File; Import Java.io.filenotfoundexception;import Java.io.filereader;import Java.io.filewriter;import Java.io.ioexception;public class Generate2 {public static void main (string[] args) {FileReader FR = null; BufferedReader br = null; FileWriter FW = NULL; BufferedWriter bw = NULL;        StringBuffer SBFF = new StringBuffer (); int i=0;        File File1 = new File ("e:\\io\\ original \\2.txt");        File file2 = null; try {fr = new FileReader (file1); br = new BufferedReader (FR); String Next;while (! ( (Next = Br.readline ()) ==null)) {if (i==0) {string[] a = Next.split (""); file2 = new File ("e:\\io\\ generates \ \" +a[1]+ ". Java"); Sbff.append ("public"); Sbff.append (next); Sbff.append ("{\ r \ n");} i++;} Sbff.append ("\ t public void Add () {}\r\n"); Sbff.append ("\ t public void Delete () {}\r\n"); Sbff.append ("\ t public void Update () {}\r\n "); Sbff.append (" \ t public void Search () {}\r\n "); SBFF.APpend ("}"), FW = new FileWriter (file2), bw = new BufferedWriter (FW); Bw.write (sbff.tostring ());} catch (FileNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Au To-generated catch Blocke.printstacktrace ();} Finally{try {br.close (); Bw.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}} </span>
Finally, the code that generates the view interface:

<span style= "FONT-SIZE:18PX;" >package com.jereh.generate;import java.io.bufferedreader;import Java.io.bufferedwriter;import java.io.File; Import Java.io.filenotfoundexception;import Java.io.filereader;import Java.io.filewriter;import Java.io.ioexception;public class Generate3 {public static void main (string[] args) {FileReader FR = null; BufferedReader br = null; FileWriter FW = NULL; BufferedWriter bw = NULL;        StringBuffer SBFF = new StringBuffer (); int i=0;        File File1 = new File ("e:\\io\\ original \\3.txt");        File file2 = null; try {fr = new FileReader (file1); br = new BufferedReader (FR); String Next;while (! ( (Next = Br.readline ()) ==null)) {if (i==0) {string[] a = Next.split (""); file2 = new File ("e:\\io\\ generates \ \" +a[1]+ ". Java"); Sbff.append ("public"); Sbff.append (next); Sbff.append ("{\ r \ n");} i++;} Sbff.append ("\ t public void AddView () {}\r\n"); Sbff.append ("\ t public void Deleteview () {}\r\n"); Sbff.append ("\ t public void Updateview () {}\r\n "); Sbff.append (" \ t public void Searchview ({}\r\n "), Sbff.append (" \ t public void Main () {\ r \ n "), sbff.append (" \ t \ t \ System.out.println (); \ r \ n "); Sbff.append (" \ t \ \ T System.out.println (); \ r \ n "); Sbff.append (" \ t \ t System.out.println (); \ r \ n "); Sbff.append (" \ t \ t System.out.println ( \ r \ n "); Sbff.append (" \ t \ t System.out.println (); \ r \ n "); Sbff.append (" \ t \ t int i = input.nextint (); \ r \ n "); sbff.append ("\ t \ r \ n"); Sbff.append ("\ t \ t \ 1:\r\n"), Sbff.append ("\ t \ t \ addview (); \ r \ n"); Sbff.append ("\ t \ t BR Eak;\r\n "); Sbff.append (" \ t \ t \ Case 2:\r\n ") sbff.append (" \ t \ t Deleteview (); { \ r \ n "), sbff.append (" \ t \ t break;\r\n "), Sbff.append (" \ t \ t case 3:\r\n "), Sbff.append (" \ t \ t Updateview (); { \ r \ n "), sbff.append (" \ t \ t break;\r\n "), Sbff.append (" \ t \ t case 4:\r\n "), Sbff.append (" \ t \ t Searchview (); { \ r \ n "); Sbff.append (" \ t \ t break;\r\n "), Sbff.append (" \ t \ t default:\r\n "); Sbff.append (" \ t \ t break;{ \ r \ n "); Sbff.append (" \ t \t}\r\n "); Sbff.append (" \ t}\r\n "); Sbff.append ("} "); fw = new FileWriter (file2); bw = new BufferedwRiter (FW); Bw.write (sbff.tostring ());} catch (FileNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Au To-generated catch Blocke.printstacktrace ();} Finally{try {br.close (); Bw.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}} </span>


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Learn Java IO character stream from scratch lazy mode (automatic generation of attribute classes, method classes, interface classes)

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.