从classpath获取文件有个好处,不管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);
}
}
}