我一直在将我的Java应用程序的所有图像放入src中的一个名为“rtype”的包中,我也有我的Class来处理这些图像。我想对图像进行排序并将它们放在自己的文件夹中。当我这样做时,图像将不再加载到类中,并且我知道这是因为我更改了文件路径。我已经做了一些研究并尝试了一些不同的东西。这基本上是我原来的:在Java应用程序中更改文件的位置
String walkingDown = "WalkingDown.gif";
ImageIcon ii;
Image image;
ii = new ImageIcon(this.getClass().getResource(walkingDown));
image = ii.getImage();
它工作得很好,然后我把图像的位置移动到类的位置以外。现在它不能找到图像。下面是我尝试过,并在网上找到的尝试(该文件夹的名称是精灵):
//use getClassLoader() inbetween to find out where exactly the file is
ii = new ImageIcon(this.getClass().getClassLoader().getResource(standingDown));
和
//Changing the path
String walkingDown = "src\\Sprites\\WalkingDown.gif";
//also tried a variation of other paths with no luck
我使用的是C盘,但不希望使用“C”在我的扩展中,因为我希望它可以访问,无论我把项目放在哪里。我在这一点上相当坚持,并且已经做了足够的研究,意识到现在是时候提问了。
什么操作系统您使用的? – sdasdadas
这里有很多关于这个的问题,例如[this one](http://stackoverflow.com/q/2343187/18573) –
我现在正在使用Windows 7。 –