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

热点内容
微信你真列害图片大全 浏览:49
jsin类型可以传数值吗 浏览:532
win10文件从左边滑出 浏览:53
win10关机后桌面文件丢失 浏览:266
watch卸载自带应用程序 浏览:292
有什么plc自学网站 浏览:219
176纯金币假人版本 浏览:334
红米note4微信计步代码 浏览:259
站长之家有app吗 浏览:912
office应用视频教程 浏览:690
html数据库有哪些 浏览:489
钢笔工具线不会变细 浏览:762
access2010数据库上机 浏览:686
flstudio录音教程 浏览:457
图形编程软件哪个好用 浏览:393
要怎么重新下载而且不保存数据 浏览:188
手机软件下载后文件在哪 浏览:515
日版苹果6黑解 浏览:799
jsp中获取mac 浏览:617
win7word备份 浏览:160

友情链接