Class vs. Classloader getResouceAsStream
In bk.sar -
conf/bkConfigSchema.sql
com.xyz.BkWirelessMgr
For classloader.getResouceAsStream(), all names are absolute, no leading "/". For class.getResourceAsStream(), it has relative and absolute path. But relative means starting from the class's package, i.e., without the leading "/", it will search com.xyz/conf/bkConfigSchema.sql, not found and return null.
Then in BkWirelessMgr class, to load the sql,
getClass().getResourceAsStream("/conf/bkConfigSchema.sql"); getClass().getClassLoader().getResourceAsStream("conf/bkConfigSchema.sql");
Note that "/" is used here instead of File.Separator which doesn't work.
No comments:
Post a Comment