I have a project (in Eclipse, but that doesn't matter) with a hierarchy as follows:
-src
---Start.java
---resources
-----media
-------intro.wav
-----textures
-------logo.png
-------tiles.abotm
In Start.java
, I'm trying to get tiles.abotm
as an InputStream using Class.getResourceAsStream(String)
as such:
public class Start
{
public static void main(String[] args)
{
try
{
InputStream in = Start.class.getResourceAsStream(
"/resources/textures/tiles.abotm");
}catch(Exception e){
e.printStackTrace();
}
}
}
Simple enough, right? Unfortunately, no. The InputStream is completely empty with a size of 0. I've also tried opening a FileInputStream directly to the absolute location of tiles.abotm
, but I get the same thing! I know the file is not empty. In fact, it has 2,257 bytes, according to Windows, Eclipse, and the File object used to create the FileInputStream mentioned previously. Also according to the File object, it is readable, writable, it exists, it is not a directory, and the name of it is tiles.abotm
. So, if the File object can read it, why can't it be opened up in an InputStream??
--EDIT--
I forgot to mention that I have another file in the textures
directory called logo.png
which I am able to open and read in the exact same manner with no problem at all. It is only this file.
--In reply to fge, this is the actual code: Loader.loadTextureMap("/resources/textures/tiles.abotm");//This is called in a separate method in a separate class.
public class Loader{
public static TextureMap loadTextureMap(String texMap){
DataInputStream dis = new DataInputStream(
Start.class.getResourceAsStream(texMap));
//It then goes on to read it, but I've determined that at this point,
there is nothing in this DataInputStream.
}
}