正常在Java工程中读取某路径下的文件时,可以采用绝对路径和相对路径,绝对路径没什么好说的,相对路径,即相对于当前类的路径.在本地工程和服务器中读取文件的方式有所不同,以下图配置文件为例. 本地读取资源文件 java类中需要读取properties中的配置文件,可以采用文件(File)方式进行读取: File file = new File("src/main/resources/properties/basecom.properties"); InputStream in = new
第一种: 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(""
public class Test { public void run() { // TODO Auto-generated method stub System.out.println("测试========>"); String s1=this.getClass().getResource("").getPath(); String s2=this.getClass().getResource("/").getPath(); Syste