eclipse java 相对路径,如何在eclipse中使用相对路径而不是绝对路径?

在Eclipse中编程时,作者发现可以将绝对路径替换为相对路径来包含其他文件。通过确保所需文件位于项目同一目录下,可以使用相对路径如'./file.txt'或'../file.txt'。此外,建议创建一个名为'resource'的项目文件夹来组织图片、图标等资源,并用'/resource/icons/...'这样的相对路径引用它们。在构建应用时可能需要展开'resource'文件夹。
摘要由CSDN通过智能技术生成

Hi

I''m programming something with java and I''m using abolute paths to include other files. My question is, are there any settings in eclipse to use only relative paths or do I have to realize this with some lines of code?

I hope someone can help me, I''m desperated :(

解决方案

Now I know I was really dumb :S

The needed file has to be in the same folder as the project p.e.:

current directory: C:\xy\xz\xx\.

absolute path of file: C:\xy\xz\xx\file.txt

relative path of file: .\file.txt

or

absolute path of file: C:\xy\xz\file.txt

relative path of file: .\..\file.txt

and so on.

Greetings

Painjofshem

Other files like pictures, icons, print templates?

- add a folder "resource" to your project aside of the folder "src"

- underneath build up a decent structure ("print", "properties", "icons")

in the code refer to these folders with a relative path: "/resource/icons/..."

You might have to unpack the resource-folders when you build your application.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值