從classpath獲取文件有個(gè)好處贬丛,不管window還是linux路徑都是一樣得;
查看classpath
System.getProperties().getProperty("java.class.path"));
class Tr{
void test(){
//從classpath獲取文件
try (InputStream input = Tr.class.getResourceAsStream("/conf.txt")) {
// TODO:
int n;
while((n=input.read())!=-1){
System.out.println((char)n);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}