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

java获取当前路径[转]

java获取当前路径[转]
关键字: java 路径
java 获取当前路径
 
1 、利用 System.getProperty() 函数获取当前路径:
System.out.println(System.getProperty("user.dir"));//user.dir 指定了当前的路径
 
2 、使用 File 提供的函数获取当前路径:
File directory = new File("");// 设定为当前文件夹
try{
    System.out.println(directory.getCanonicalPath());// 获取标准的路径
    System.out.println(directory.getAbsolutePath());// 获取绝对路径
}catch(Exceptin e){}
 
File.getCanonicalPath() 和 File.getAbsolutePath() 大约只是对于 new File(".") 和 new File("..") 两种路径有所区别。
 
# 对于 getCanonicalPath() 函数,“ ." 就表示当前的文件夹,而” .. “则表示当前文件夹的上一级文件夹
# 对于 getAbsolutePath() 函数,则不管” . ”、“ .. ”,返回当前的路径加上你在 new File() 时设定的路径
# 至于 getPath() 函数,得到的只是你在 new File() 时设定的路径
 
比如当前的路径为 C:\test :
File directory = new File("abc");
directory.getCanonicalPath(); // 得到的是 C:\test\abc
directory.getAbsolutePath();    // 得到的是 C:\test\abc
direcotry.getPath();                    // 得到的是 abc
 
File directory = new File(".");
directory.getCanonicalPath(); // 得到的是 C:\test
directory.getAbsolutePath();    // 得到的是 C:\test\.
direcotry.getPath();                    // 得到的是 .
 
File directory = new File("..");
directory.getCanonicalPath(); // 得到的是 C:\
directory.getAbsolutePath();    // 得到的是 C:\test\..
direcotry.getPath();                    // 得到的是 ..
 
关于System.getProperty方法的参数见
System.getProperty


相关文档:

java 操作短信猫实现短信群发

采用串口操作进行短信收发,是比较常见的一种方式.比如,很多群发软件,用的就是这种方法.
1.配置comm.jar.
Comm.jar是Sub实现底层串口操作的API,调用了本地的DLL文件,因为Java本身不具备直接访问硬件设置的能力,都是通过调用本地方法来实
现的.可以Java的官方网站下载.下载之后把其中Comm.jar包导入到工程的Classpath中,把 ......

java伪静态 文件防盗链的实现


现在UrlRewriter技术有两个技术平台的,一个就是在Java方向的,另一个就是.NET方向的。这次是Java方向的应用。
首先让我们了解它的工作原理,说白了它就是一个简单的过滤器(Filter),看看源码你就会很快的明白,它就是通过我们在jsp中常用的两个方法实现的forward(),sendRedirect().
下面我们就快速的为你的网站搭建U ......

java中与(&)和或(|)运算

System.out.println(2|0); //0010 0000 =>0010 = 2
System.out.println(2|1); //0010 0001 =>0011 = 3
System.out.println(3|2); //0011 0010 =>0011 = 3
System.out.println(3&2); //0011 0010 =>0010 = 2
/*
  在java中0代表假, 1代表真
  00011|0010  从右到左比较0|1 = 1, 1|0 = ......

java存储过程的创建与调用

create or replace procedure updateProject is  
begin  
  update project p set p.total_intend_gather =   
  (select sum(ig.gather_sum) from intend_gather ig where ig.project_number=p.project_number);  
    
  up ......

JAVA基础--JAVA中的反射机制详解

转贴:http://java.ccidnet.com/art/3539/20070924/1222147_1.html
 
JAVA反射机制
    JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意一个方法;这种动态获取的信息以及动态调用对象的方法的功能称为java语言的反射机 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号