导航:首页 > 编程语言 > 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获取提示框输入的路径相关的资料

热点内容
手机如何删除删除不了的app 浏览:212
编程怎么走好路 浏览:417
小米游戏数据一般在哪个文件 浏览:902
桌面服务器是哪个文件 浏览:965
二进制数据类型的长度为什么是n4 浏览:561
js获取当前js文件的路径 浏览:106
adobeindesigncs6教程 浏览:909
猿编程怎么玩游戏 浏览:603
win8无网络访问权限 浏览:121
一个数据库大小限制多少g 浏览:760
无限斯特拉托斯可以用哪些app看 浏览:954
图片与拍摄文件大小名词解释 浏览:229
java的classpath配置文件 浏览:286
在小年鱼app里面如何退款 浏览:143
网络电话哪个软件好用吗 浏览:386
pokemon叫声文件 浏览:689
工程源文件路径 浏览:137
cad高版本能否打开低版本文件 浏览:430
金山1kb病毒专杀工具 浏览:371
面试官大数据处理需要问什么问题 浏览:842

友情链接