自动构建java包
2015-10-01 20:32
716 查看
package test; import java.io.File; import java.io.FileOutputStream; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import org.junit.Test; public class AutoCreateFile { @Test public void createSource(){ // String proPath = System.getProperty("user.dir") + "\\src"; String proPath = System.getProperty("user.dir"); System.out.println(proPath); File f = new File(proPath+"/myconfig"); if(!f.exists()){ System.out.println("--------->创建源文件<------------"); try { f.mkdir(); File classpathFile = new File(proPath+"/.classpath"); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(classpathFile); // Element root = document.getRootElement(); Element newDom = DocumentHelper.createElement("classpathentry"); newDom.setAttributeValue("kind", "src"); newDom.setAttributeValue("path", "myconfig");// root.add(newDom); XMLWriter writer = new XMLWriter(new FileOutputStream(classpathFile)); writer.write(document); writer.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ System.out.println("--------->你所创建的源文件已存在<------------"); } } @Test public void createPackage(){ System.out.println("------------>创建package "); File src = new File("src/com/md5"); System.out.println(src.getAbsolutePath()); /* * File [] files = src.listFiles(); for(File f: files){ System.out.println(f.getAbsolutePath()); } */ System.out.println("------------>创建package<-------------end "); } }
相关文章推荐
- Java基础知识强化之集合框架笔记08:Collection集合自定义对象并遍历案例(使用迭代器)
- Java多线程4:synchronized锁机制
- java12 :排序
- Java Comparator 排序
- Java 调用dll
- spring4 quartz2 集群动态任务
- Java基础知识强化之集合框架笔记07:Collection集合的遍历之迭代器遍历
- Java内存模型之运行时数据区域
- Java环境变量配置
- Java基础知识强化之集合框架笔记06:Collection集合存储自定义对象并遍历的案例
- Java中判断字符串是否为数字的五种方法
- java连接mysql的一个小例子
- [转载] java中静态代码块的用法 static用法详解
- Java基础知识强化之集合框架笔记05:Collection集合的遍历
- Java 中的内存泄露
- java菜鸟1:jdk 安装
- Java基础知识强化之集合框架笔记04:Collection集合的基本功能测试
- Java基础知识强化之集合框架笔记03:Collection集合的功能概述
- springmvc整合mybatis出现Could not autowire field:No matching bean of type错误
- JDK环境变量配置