java 文件读写
来源:互联网 发布:北京公司招聘程序员 编辑:程序博客网 时间:2024/06/03 00:43
public class CodeGenerate {
/**
* 1 传入你要生成的类名 Company
* 2 将模板文件(dist/model) copy到 c:/dist 下,
* 3 执行代码,对应的代码生产到你的project根目录中,project中要有对应的目录
* src/
* com/
* hxd/
* company/
* bo
* ctrl
* impl
* vo
* 4 将你 Company的po中的属性 copy的 生成的CompanyForm中 并生成相应的setter getter
* 5 将config.xml 中的代码copy到对应的struts-config.xml 中
* 6 将 其他的java jsp 文件copy到对应目录中,jsp文件要在 page下创建一个company的目录,
* jsp就copy到这里
* 7 改动针对该 模块的显示jsp
* 8 run tomcat ^_^
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
* 1 传入你要生成的类名 Company
* 2 将模板文件(dist/model) copy到 c:/dist 下,
* 3 执行代码,对应的代码生产到你的project根目录中,project中要有对应的目录
* src/
* com/
* hxd/
* company/
* bo
* ctrl
* impl
* vo
* 4 将你 Company的po中的属性 copy的 生成的CompanyForm中 并生成相应的setter getter
* 5 将config.xml 中的代码copy到对应的struts-config.xml 中
* 6 将 其他的java jsp 文件copy到对应目录中,jsp文件要在 page下创建一个company的目录,
* jsp就copy到这里
* 7 改动针对该 模块的显示jsp
* 8 run tomcat ^_^
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
CodeGenerate codeGenerate = new CodeGenerate("PmCheck");
codeGenerate.createAllFile();
}
public CodeGenerate(String newFile){
this.newFile=newFile;
}
codeGenerate.createAllFile();
}
public CodeGenerate(String newFile){
this.newFile=newFile;
}
String newFile = "";
public void createFile(String beforeTxt, String oldClass, String afterTxt,
String newClass) {
String FileName = "C://dist//" + beforeTxt + oldClass + afterTxt;
System.out.println(beforeTxt + oldClass + afterTxt);
System.out.println("========" + FileName);
File myFile = new File(FileName);
if (!myFile.exists()) {
System.err.println("Can't Find " + FileName);
return;
}
FileReader filereader;
try {
filereader = new FileReader(myFile);
String line = "";
BufferedReader read = new BufferedReader(filereader);
public void createFile(String beforeTxt, String oldClass, String afterTxt,
String newClass) {
String FileName = "C://dist//" + beforeTxt + oldClass + afterTxt;
System.out.println(beforeTxt + oldClass + afterTxt);
System.out.println("========" + FileName);
File myFile = new File(FileName);
if (!myFile.exists()) {
System.err.println("Can't Find " + FileName);
return;
}
FileReader filereader;
try {
filereader = new FileReader(myFile);
String line = "";
BufferedReader read = new BufferedReader(filereader);
try {
FileWriter fw = new FileWriter(beforeTxt + newClass + afterTxt);
PrintWriter out = new PrintWriter(fw);
String cc = "";
while ((line = read.readLine()) != null) {
cc = line.replaceAll("Commodity", newClass);
cc = cc.replaceAll("commodity", this.trans(newClass));
System.out.println(cc);
out.println(cc);
// fw.write(cc, 0, cc.length());
}
FileWriter fw = new FileWriter(beforeTxt + newClass + afterTxt);
PrintWriter out = new PrintWriter(fw);
String cc = "";
while ((line = read.readLine()) != null) {
cc = line.replaceAll("Commodity", newClass);
cc = cc.replaceAll("commodity", this.trans(newClass));
System.out.println(cc);
out.println(cc);
// fw.write(cc, 0, cc.length());
}
// ------------
fw.flush();
out.close();
filereader.close();
fw.close();
fw.flush();
out.close();
filereader.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void createAllFile() {
String oldFile = "Commodity";
String oldFile = "Commodity";
createFile("", oldFile, "Bo.java", newFile);
createFile("", oldFile, "Action.java", newFile);
createFile("", oldFile, "Decorator.java", newFile);
createFile("", oldFile, "Form.java", newFile);
createFile("", oldFile, "Impl.java", newFile);
// ------------------------------
createFile("add", oldFile, ".jsp", newFile);
createFile("edit", oldFile, ".jsp", newFile);
createFile("view", oldFile, ".jsp", newFile);
createFile("show", oldFile, ".jsp", newFile);
createFile("", oldFile, "Action.java", newFile);
createFile("", oldFile, "Decorator.java", newFile);
createFile("", oldFile, "Form.java", newFile);
createFile("", oldFile, "Impl.java", newFile);
// ------------------------------
createFile("add", oldFile, ".jsp", newFile);
createFile("edit", oldFile, ".jsp", newFile);
createFile("view", oldFile, ".jsp", newFile);
createFile("show", oldFile, ".jsp", newFile);
// ----------------------
createFile("", "config", ".xml", newFile);
}
createFile("", "config", ".xml", newFile);
}
public String trans(String cc) {
String head = cc.substring(0, 1);
String tail = cc.substring(1, cc.length());
System.out.println(head);
System.out.println(head.toLowerCase() + tail);
return head.toLowerCase() + tail;
}
String head = cc.substring(0, 1);
String tail = cc.substring(1, cc.length());
System.out.println(head);
System.out.println(head.toLowerCase() + tail);
return head.toLowerCase() + tail;
}
本文转自: http://www.knowsky.com/361358.html
- java 读写ini文件
- java读写文件
- Java读写文件方法
- java 读写属性文件
- JAVA同时读写文件
- java 文件读写
- java文件读写
- JAVA IO读写文件
- java读写磁盘文件
- Java gzip文件读写
- Java读写Zip文件
- java读写文件
- java读写文件大全
- java 读写 ini 文件
- JAVA 文件读写
- java 读写文件大全
- java 读写文件大全
- java文件读写
- 木制键盘
- 为什么java不允许 super.super.xxx 这样的语句?老孙之看法,欢迎分享交流
- Groovy探索之闭包 五
- 呵呵,CSDN改版了,我要回来了
- java判断星期(可输入日期)
- java 文件读写
- 初来CSDN,各位前辈多多指教,本文为自我介绍。
- CodeSmith基础(一) -------- 转自博客园
- 标签打印机常见问题
- 查找某个字符在字符串中第N次出现的位置
- 在服务器端取得HTML控件的值
- 用代码修改Web.Config里的键值
- 合并列值
- Iframe专题