易截截图软件、单文件、免安装、纯绿色、仅160KB

java 绝对路径工具类

在程中我们常取一些资源的绝对径,下面给出一个简单方便的工具类来帮助我们轻松的找到我想的资源。(适用于CS/BS应用)
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/** *//**
* @author <a href="mailto:maryang@live.cn" mce_href="mailto:maryang@live.cn">Maryang</a>
* @version $Revision: 1.0 $
* 这个类提供了一些根据类的class文件位置来定位的方法。
*/
public class PathUtil {

/** *//**
* 获取一个Class的绝对路径
* @param clazz Class对象
* @return Class的绝对路径
*/
public static String getPathByClass(Class clazz){
String path = null;
try {
URI uri = clazz.getResource("").toURI();
File file = new File(uri);
path = file.getCanonicalPath();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return path;
}

/** *//**
* 获取一个文件相对于一个Class相对的绝对路径
* @param clazz Class对象
* @param relativePath Class对象的相对路径
* @return 文件绝对路径
*/
public static String getFilePathByClass(Class clazz,String relativePath){
String filePath = null;
String clazzPath = getPathByClass(clazz);
StringBuffer sbPath = new StringBuffer(clazzPath);
sbPath.append(File.separator);
sbPath.append(relativePath);
File file = new File(sbPath.toString());
try {
filePath = file.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
return filePath;
}
public static void main(String[] args) {
try {
System.out.println(getPathByClass(PathUtil.class));
System.out.println(getFilePathByClass(PathUtil.class,"../../images/logo.gif"));
} catch (Exception


相关文档:

sql 2005 存储过程分页 java 代码

 create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',         
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列 ......

【Java App Convert to EXE File】

* ------------------------------------------------------------------------------------
Title:    TestJava.cpp
author: gloomy fish on 2009-09-16
------------------------------------------------------------------------------------ */
#include <windows.h>
#include <stdio.h& ......

JAVA学习网址大全

    在学习JAVA的过程中,我查阅了许多有关学习JAVA的网络资源,我把它们汇总到了一起把这些资源保存起来如下列出:
       java开发学习网址大全
1.维基百科,自由的百科全书
http://zh.wikipedia.org/wiki/HTML
2.w3school网
http://www.w3school.com.cn/
3.JAVA中文首页 ......

Java调用外部程序

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class CmdTest {
    private static final long serialVersionUID = -2650474785662737262L;
    public static void main(String[] args) throws Exception {
  &n ......

Java搜索算法测试

任何项目开发中,在一个集合或数组中循环查找,搜索目标数据,是经常用到的。如果搜索的数据范围比较小,那么不管什么算法,对于今天的计算机来说,性能上基本差别不大,但是如果数据量达到几百万,甚至更大,那么算法的选择和优化就显得比较重要。有空之余测试了下顺序搜索和二分搜索的性能,竟然发现效率差异在1500倍左右 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号