导航:首页 > 编程语言 > java获取提示框输入的路径

java获取提示框输入的路径

发布时间:2023-08-31 13:11:38

『壹』 在java中怎么获取页面的路径

第一种:
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
结果:
C:Documents%20and%
获取当前类的所在工程路径;
如果不加“/”
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
结果:
C:Documents%20and%comtest
获取当前类的绝对路径;
第二种:
File directory = new File("");//参数为空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
结果:
C:Documents and
获取当前类的所在工程路径;
第三种:
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);
结果:
file:/C:/Documents%20and%
20Settings/Administrator/workspace/projectName/bin/selected.txt
获取当前工程src目录下selected.txt文件的路径
第四种:
System.out.println(System.getProperty("user.dir"));
结果:
C:Documents and
获取当前工程路径
第五种:
System.out.println( System.getProperty("java.class.path"));
结果:
C:Documents and bin

『贰』 在java中如何获取文件夹路径。类似在邮箱里面那种上传附件的形式,通过弹去对话框来选中文件夹来获取。

web程序的话利用表单控件file就可以获取文件路径了,后台利用文件流获取文件

『叁』 Java应用程序怎样点击按钮弹出文件查找路径的窗口

1、js弹出文件选择框:
给按钮定义以下javascript函数:

var inputObj=document.createElement('input')
inputObj.setAttribute('id','_ef');
inputObj.setAttribute('type','file');
inputObj.setAttribute("style",'visibility:hidden');
document.body.appendChild(inputObj);
inputObj.click();
inputObj.value ;

单击已经添加函数的按钮会弹出选择本地文件的对话框。
2、写一个隐藏域, 当用户选择文件之后把图片的路径赋给这个隐藏域, 然后在action中就可以获取到文件的路径了,代码如下:

function showRealPath(filePath){
document.getElementsByName("textfield")[0].value = filePath;
}
<input type="file" name="uploadfile" onfocus="showRealPath(this.value);"/>
<input type="hidden" name="uploadfileRealPath">

『肆』 Java获取路径的几种方式

获取当前类的绝对路径;第1种:File directory = new File("");//参数为空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);结果:C:\Documents and Settings\Administrator\workspace\projectName
获取当前类的所在工程路径;第2种:URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);结果:file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt
获取当前工程src目录下selected.txt文件的路径第3种:System.out.println(System.getProperty("user.dir"));结果:C:\Documents and Settings\Administrator\workspace\projectName
获取当前工程路径第4种:System.out.println( System.getProperty("java.class.path"));结果:C:\Documents and Settings\Administrator\workspace\projectName\bin获取当前工程路径

阅读全文

与java获取提示框输入的路径相关的资料

热点内容
哪些统计量可以反映数据波动 浏览:946
js地图标记怎么清空 浏览:479
googlenow教程 浏览:508
安全四个责任体系内容文件 浏览:965
南阳政务app怎么注册 浏览:343
照片压缩包同一路径的文件能删吗 浏览:590
路由没网络怎么办 浏览:745
南京网站推广大概多少钱 浏览:983
js隐藏打印出来 浏览:135
手工之家app哪里下载 浏览:328
网络教育联盟英语考试是什么 浏览:69
macairwin10忘记密码 浏览:716
java上传方法 浏览:970
csc文件夹可以删除吗 浏览:130
打线工具怎么用 浏览:376
mat文件如何转换为cad 浏览:761
qq浏览器旧版本614 浏览:713
将数据库文件批量导出excel 浏览:262
招投标文件在招标公司存多少年 浏览:551
u盘空间不足不能复制系统镜像文件 浏览:212

友情链接