WEB开发网
开发学院WEB开发Jsp 一个最简单的 JavaBeanMaker(原创) 阅读

一个最简单的 JavaBeanMaker(原创)

 2008-01-05 09:38:10 来源:WEB开发网   
核心提示:只实现最简单功能,自动生成setter,getter当bean中属性较多时可以节省时间:Usage: java JavaBeanMaker aaa.txt bbb 1. aaa.txt is the text file in following style,you can get a example--jeru.txt

  只实现最简单功能,自动生成setter,getter当bean中属性较多时可以节省时间:

Usage: java JavaBeanMaker aaa.txt bbb

1. aaa.txt is the text file in following style,you can get a example--jeru.txt in attachment
  ======================
  int id
  String name
  int age
  ======================

2 bbb is the file name of your javabean without .java,so if you want a Test.java
  just type "Java JavaBeanMaker aaa.txt Test"

================= jeru.txt ==========================
int id
String name
int age
================= JavaBeanMaker.java ================
import java.io.*;
import java.util.*;

public class JavaBeanMaker {
 
 public static void main(String[] args) {
  System.out.PRintln("Reading datas......");
   try {
    // read properties of source text file
  int i = 0;
  String record = new String();
  Vector property = new Vector();
    RandomaccessFile source = new RandomAccessFile(args[0],"r");
    while ((record = source.readLine()) != null) {
     i ++;
     property.addElement(record);    
    }
    source.close();
   
  RandomAccessFile destine = new RandomAccessFile(args[1],"rw");
    String content = "// This JavaBean is make by Jeru's JavaBeanMaker" + "\r\n\r\n";
    content += "public class " + args[1] + " {" + "\r\n\r\n";
   
  String[] tmp = new String[3];
  for (i=0; i<property.size(); i++) {
   String str = (String)property.elementAt(i);
   //System.out.println("Value " + i + ":" + str);
   StringTokenizer tokens = new StringTokenizer(str);

Tags:一个 简单 JavaBeanMaker

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接