您的位置:首页 > 编程语言 > Java开发

数据字典生成Java代码

2013-11-26 23:02 393 查看
import java.io.*;

import java.util.ArrayList;

import java.util.Scanner;

import java.util.zip.ZipEntry;

/**

 * @authour xiujian zeng

 * @date 2013-11-7

 */
/*

直接输入文件名称如(aa或者d:aa)一个是在工程中,另一个是在d盘中(注意:不要写成xxx.txt)

 * 验证信息    

zhang

lei

z

l

13515455767

leileileileiaideni@qq.com

0621

1987

 */

public class DataDic {

static File file;
static FileWriter fileWriter;
static BufferedWriter bufferedWriter;

static DataDic dataDic;

public static void main(String[] args) throws IOException {
dataDic = new DataDic(); // 初始化类
dataDic.getInformation();
}

ArrayList<String> arrayList;   //进行全排的列表
private static String firstname;// 姓
private static String lastname;// 名
private static String firstnaJX;// 姓简写
private static String lastnaJX;// 名简写
private static String tel;// 电话号码
private static String email;// 邮箱
private static String birthday;// 生日
//private static String xuehao;// 学号
private static String fileName;// 生成的文件名称
private static String birYearS; //出身年份
private static String birPlace; //出身地

public void enterFile(ArrayList<String> arrayList) throws IOException { // 输入到文件
for (int j = 0; j < arrayList.size(); j++) {
bufferedWriter.write(arrayList.get(j));
}
bufferedWriter.newLine();
bufferedWriter.flush();
// bufferedWriter.close();
}

public void swap(int i, int k) {
String temp;
temp = arrayList.get(k);
arrayList.set(k, arrayList.get(i));
arrayList.set(i, temp);
}

public void getAllKey(ArrayList<String> arrayList, int k)
throws IOException {// 递归全排列
if (k == arrayList.size() - 1) {
dataDic.enterFile(arrayList);
} else {
for (int j = k; j < arrayList.size(); j++) {
dataDic.swap(j, k);
dataDic.getAllKey(arrayList, k + 1);
dataDic.swap(j, k);
}
}
}

public void getInformation() throws IOException { // 输入信息
ArrayList<String> arrayList2 = new ArrayList<String>();
System.out.println("Please enter the file path:");
Scanner read = new Scanner(System.in);
fileName = read.nextLine();
file = new File(fileName + ".txt");
fileWriter = new FileWriter(file);
bufferedWriter = new BufferedWriter(fileWriter);
System.out.println("Please enter information");
firstname = read.nextLine();
lastname = read.nextLine();
firstnaJX = read.nextLine();
lastnaJX = read.nextLine();
tel = read.nextLine();
email = read.nextLine();
birthday = read.nextLine();
//xuehao = read.nextLine();
birYearS=read.next();
String[] email1 = email.split("@");// 拆分解析邮箱名称
email = email1[0];

arrayList2.add(tel);
arrayList2.add(email);
arrayList2.add(firstname);
arrayList2.add(lastname);
arrayList2.add(firstnaJX);
arrayList2.add(lastnaJX);
arrayList2.add(birthday);
//arrayList2.add(xuehao);
arrayList2.add(birYearS);
for (int i = 0; i < arrayList2.size(); i++) {   //
for (int r = 0; r < arrayList2.size(); r++) {  //密码位数控制
arrayList = new ArrayList<String>();
for (int j = i + r, k = 0; j < arrayList2.size(); j++, k++) { //从第一位一次往后加
arrayList.add(0, arrayList2.get(j));
dataDic.getAllKey(arrayList, 0);
}
arrayList = new ArrayList<String>();
for (int j = arrayList2.size()-1, k = 0; j >0 ; j--, k++) {  //从最后一位一次往前加,不取第一位否则重复
arrayList.add(0, arrayList2.get(j));
dataDic.getAllKey(arrayList, 0);
}
}

}
bufferedWriter.close();
}

/**
* @param fileName
*            the fileName to set
*/
public static void setFileName(String fileName) {
DataDic.fileName = fileName;
}

/**
* @return the fileName
*/
public static String getFileName() {
return fileName;
}

/**
* @return the tel
*/
public static String getTel() {
return tel;
}

/**
* @param tel
*            the tel to set
*/
public static void setTel(String tel) {
DataDic.tel = tel;
}

/**
* @return the email
*/
public static String getEmail() {
return email;
}

/**
* @param email
*            the email to set
*/
public static void setEmail(String email) {
DataDic.email = email;
}

/**
* @return the birthday
*/
public static String getBirthday() {
return birthday;
}

/**
* @param birthday
*            the birthday to set
*/
public static void setBirthday(String birthday) {
DataDic.birthday = birthday;
}
public static void setBirYearS(String birYearS) {
DataDic.birYearS = birYearS;
}

public static String getBirYearS() {
return birYearS;
}

public static void setBirPlace(String birPlace) {
DataDic.birPlace = birPlace;
}

public static String getBirPlace() {
return birPlace;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据字典