Skip to content

Instantly share code, notes, and snippets.

@shangoyanyi
Created September 15, 2017 07:43
Show Gist options
  • Save shangoyanyi/02988c63dbe24dae2212ea9e2e62e5ef to your computer and use it in GitHub Desktop.
Save shangoyanyi/02988c63dbe24dae2212ea9e2e62e5ef to your computer and use it in GitHub Desktop.
how to read resource in JavaEE
public class ResourceReader{
/*
* filePath 是檔案所在的 package ,將 "." 改為 "/"
* 例如檔案 config.txt 所在 package 是 my.resource
* 則 filePath = "my/resource/config.txt"
*/
public void readResource(String filePath){
InputStream in = ResourceReader.class.getClassLoader().getResourceAsStream(filePath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment