html怎么通过file获取文件路径

html-css010

html怎么通过file获取文件路径,第1张

html通过file获取文件路径方法:第一种: File f = new File(this.getClass().getResource("/").getPath())System.out.println(f)结果: C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin 获取当前类的所在工程路径如果不加“/” File f = new File(this.getClass().getResource("").getPath())System.out.println(f)结果: C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test 获取当前类的绝对路径; 第二种: File directory = new File("")//参数为空 String courseFile = directory.getCanonicalPath() System.out.println(courseFile)结果: C:\Documents and Settings\Administrator\workspace\projectName 获取当前类的所在工程路径第三种: 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文件的路径

htmlfile是html格式的文件,它其实是特殊的文本文件。它需要浏览器的解释,每种HTML标记符在使用中可带有不同的属性项,用于描述该标记符说明的内容显示不同的效果。html又称超文本标记语言,结构包括头部分(Head)、和主体部分(Body),其中头部(head)提供关于网页的信息,主体(body)部分提供网页的具体内容。

用accept属性,如下:

<input type="file" name="image" id="image" accept=".jpg">

这个属性是html5规定的,因此浏览器必须兼容或支持html5,比如ie10+, chrome, firefox等。

别忘记在网页开头写上<!doctype html>以声明支持html5。