Java – getresourceasstream() returns a stream with empty content
•
Java
I have a small java project in eclipse The project has a SRC and bin folder (typical), and Src is added to the classpath I run on windows
The following calls are valid:
System.out.println(TestINI.class.getResource("happytest.ini"));
The path where it prints the file:
file:/D:/work/baton/Touch/JTouch/bin/com/interra/tests/happytest.ini
I checked the contents of the INI file mentioned above. It has the expected contents
But read from the file as follows:
InputStream is = TestINI.class.getResourceAsStream("happytest.ini");
Gave me an input stream without content That is, it returns a zero byte file
My eclipse is 3.6 Helios 64 bit running on Windows 7
Google search shows that the resource path or input stream is empty, but this is not the case
The classpath entries are as follows:
<classpathentry kind="src" path="src"/> ... other class path entries for libraries like ini4j <classpathentry kind="output" path="bin"/>
Solution
That's what Jim garrison said - you edit the file in 'SRC' and read it from 'bin'
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码