Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try the next:</p> <pre><code>ClassLoader classloader = Thread.currentThread().getContextClassLoader(); InputStream is = classloader.getResourceAsStream("test.csv"); </code></pre> <hr> <p>If the above doesn't work, various projects have been added the following class: <a href="http://grepcode.com/file/repo1.maven.org/maven2/com.opensymphony/xwork/2.1.3/com/opensymphony/xwork2/util/ClassLoaderUtil.java" rel="noreferrer"><strong><code>ClassLoaderUtil</code></strong></a><sup>1</sup> (code <a href="http://grepcode.com/file_/repo1.maven.org/maven2/com.opensymphony/xwork/2.1.3/com/opensymphony/xwork2/util/ClassLoaderUtil.java/?v=source" rel="noreferrer">here</a>).<sup>2</sup></p> <p>Here are some examples of how that class is used:</p> <pre><sub>src\main\java\com\company\test\YourCallingClass.java src\main\java\com\opensymphony\xwork2\util\ClassLoaderUtil.java src\main\resources\test.csv</sub></pre> <pre><code>// java.net.URL URL url = ClassLoaderUtil.getResource("test.csv", YourCallingClass.class); Path path = Paths.get(url.toURI()); List&lt;String&gt; lines = Files.readAllLines(path, StandardCharsets.UTF_8); </code></pre> <pre><code>// java.io.InputStream InputStream inputStream = ClassLoaderUtil.getResourceAsStream("test.csv", YourCallingClass.class); InputStreamReader streamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(streamReader); for (String line; (line = reader.readLine()) != null;) { // Process line } </code></pre> <hr> <p><em>Notes</em></p> <ol> <li><a href="https://web.archive.org/web/20171212030426/http://grepcode.com/file/repo1.maven.org/maven2/com.opensymphony/xwork/2.1.3/com/opensymphony/xwork2/util/ClassLoaderUtil.java" rel="noreferrer">See it</a> in <em>The Wayback Machine</em>.</li> <li>Also in <a href="https://github.com/krosenvold/struts2/blob/master/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java" rel="noreferrer">GitHub</a>.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload