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

热点内容
网络小说用什么写 浏览:956
扩展名为rm的文件如何打开 浏览:707
导入android项目没有rjava 浏览:899
带英文和数字的文件名 浏览:843
黄山数控编程培训在哪里 浏览:111
win10侠盗5无限读取 浏览:557
js工厂模式 浏览:927
iphone6s清理缓存 浏览:465
ug编程怎么选不上字体 浏览:435
pc文件加密哪个好 浏览:393
苹果软件更新4位密码 浏览:96
手机如何将文件弄成文件夹 浏览:275
swordigo第四关 浏览:996
t420win10网卡驱动 浏览:805
ps怎么打开dxf文件怎么打开 浏览:698
ps格式文件打开软件 浏览:371
下载网络资源遇到哪些问题 浏览:887
抖音交友app广告怎么投 浏览:870
esxiha配置文件 浏览:573
pubg交易平台有哪些APP 浏览:144

友情链接