创建文件


  public boolean createFile(String _fileName, StringBuffer buf) {
    File file1 = new File(_fileName);
    if (!file1.exists()) {
      try {
        file1.createNewFile();
        FileOutputStream outfs = new FileOutputStream(file1);
        outfs.write(buf.toString().getBytes());
      }
      catch (Exception ex) {
        System.out.println(_fileName + "  file Create failure!");
        return false;
      }
    }
    return true;
  }

 

 


  //创建和类相关的目录
  public String mkdirs(Object obj, String baseDdir) {
    Class m_class = obj.getClass();
    StringBuffer _n = new StringBuffer(baseDdir);
    String _className = m_class.getName();
    for (int k = 0; k < _className.length(); k++) {
      char c = _className.charAt(k);
      if (".".getBytes()[0] == c) {
        _n.append("");
      }
      else {
        _n.append(c);
      }

    }
    File file1 = new File(_n.toString());
    if (!file1.exists()) {
      file1.mkdirs();
    }
    return _n.toString();

  }

 


//获取当前类的上一个包的名称
  public String getUpPackageName(Object obj, String prefix) {
    Class m_class = obj.getClass();
    String packageName = m_class.getPackage().getName();
    return packageName.substring(0, packageName.lastIndexOf(prefix) - 1);

  }
  //获取当前类的名称
  public String getCurrentClassName(Object obj) {
    Class m_class = obj.getClass();
    String packageName = m_class.getPackage().getName();
    String className=m_class.getName();
    String[] _class    =className.split("//.");
    System.out.println(_class.length);
    for(int i=0;i<_class.length;i++)
    {
      System.out.println(_class[i]);
    }
    String result= className.substring(className.lastIndexOf(packageName),className.length());

    return result;
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值