基本概念的理解
绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)。
相对路径:相对与某个基准目录的路径。包含Web的相对路径(HTML中的相对目录)。
相对路径和绝对路径。
package test;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Test;
public class InputFileTest {
@Test
public void testPath() throws IOException {
//使用绝对路径
InputStream in = new FileInputStream("D:\\upload\\ardv20161014133503355.jpg");
//获取根目录下的文件
//InputStream in = this.getClass().getResourceAsStream("/db.properties");
//InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties");
//获取当前类路径下的文件
//InputStream in = this.getClass().getResourceAsStream("test.xml");
//InputStream in = this.getClass().getClassLoader().getResourceAsStream("test.xml");
int length = in.available();
byte[] b = new byte[length];
in.read(b);
System.out.println(new String(b));
}
}