在Mac上的Eclipse src文件夹中图像文件的路径 [英] Path for image file in Eclipse src folder, on a Mac

查看:147
本文介绍了在Mac上的Eclipse src文件夹中图像文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载图像文件.

I'm trying to load an image file.

File imageCheck = new File("Users/me/Documents/workspace/ChineseChess/src/RCar.gif");
if (imageCheck.exists())
    System.out.println("Image file found!");
else
    System.out.println("Image file not found! :(");
button.setIcon(new ImageIcon("Users/me/Documents/workspace/ChineseChess/src/RCar.gif"));

  1. 我应该将RCar.gif放在eclipse项目的src或bin文件夹中吗?
  2. 在没有显式路径的情况下,我将如何引用它? (我使用的是Mac.我相信应该是〜/RCar.gif之类的东西,但在网上找不到正确的语法时遇到了麻烦.

谢谢!

推荐答案

如果要使用相对路径,则它们将相对于项目的根目录,或相对于jar文件所在目录的部署.您可以使用src/RCar.gif作为文件名.

If you want to use relative paths, they are going to be relative to the project's root, or when its deployed, the directory that the jar file resides in. You can use src/RCar.gif as your filename.

最好为资源创建一个单独的文件夹,然后用new File("res/RCar.gif");进行寻址.另一种选择是将它们放置在src文件夹中,并使用类加载器对其进行寻址.

It would be better if you created a separate folder for resources, then address them with new File("res/RCar.gif"); Another option is to put them in the src folder and address them using the classloader.

这篇关于在Mac上的Eclipse src文件夹中图像文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆