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;
}