⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dealsystem.java

📁 J2EE eclipse 下开发数据库一个插件
💻 JAVA
字号:
/*
 * Created on 2003-4-9
 *
 */
package com.tanghan.util;

import java.net.URL;
import java.io.File;
/**
 * @author Jerry Tang
 * @version v0.1.0
 * @copyright  (C) 2003 Tanghan工作组
 *  */
public class DealSystem {
	/** 得到一个类的包的根路径
	 * @param cls 
	 * @return 根路径
	 */
	public static String getClassRootPath(Class cls){
		String porpoiseHome = null;
//		System.out.println(cls.toString());
		ClassLoader systemClassLoader =cls.getClassLoader();
		if (systemClassLoader == null) {
			System.out.println("ClassLoader error") ;
		}
		else {
			String className =cls.getName().replace('.', '/') + ".class";
			URL classResource = systemClassLoader.getResource(className);
			String fileComponent = classResource.getFile();
//			System.out.println(fileComponent);
			File dir=new File(fileComponent);
			String dirName=dir.toString();
			dirName = dirName.substring(0,(dirName.length()-className.length()));
			porpoiseHome =  dirName;			
		}
		if (porpoiseHome == null) {
			System.out.println("Unable to find the root path of class");
		}
		return porpoiseHome;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -