标题 | jsp中获取当前目录的方法 |
范文 | 本文实例讲述了jsp中获取当前目录的实现方法,分享给大家供大家参考。具体实现方法如下: 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:testabc directory.getabsolutepath(); //得到的是c:testabc 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(); //得到的是.. 获取 java 程序当前的工作目录 代码如下: file file = new file(t.tmp); string fullpath = file.getabsolutepath(); ① request.getrealpath: 方法:request.getrealpath(/) 得到的路径:c:program filesapache software foundationtomcat 5.5webappsstrutstest 方法:request.getrealpath(.) 得到的路径:c:program filesapache software foundationtomcat 5.5webappsstrutstest. 方法:request.getrealpath() 得到的路径:c:program filesapache software foundationtomcat 5.5webappsstrutstest 方法:request.getrealpath(web.xml) 得到的路径:c:program filesapache software foundationtomcat 5.5webappsstrutstestweb.xml ② request.getparameter(); actionform.getmyfile(); 方法:string filepath = request.getparameter(myfile); 得到的路径:d:vss安装目录users.txt 方法:string filepath = actionform.getmyfile(); 得到的路径:d:vss安装目录users.txt 希望本文所述对大家的jsp程序设计有所帮助。 |
随便看 |
|
在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。