Ale*_*ian 32 java eclipse resources android
如何使用代码获取项目中文件夹的相对路径?
我在我的项目中创建了一个新文件夹,我想要它的相对路径,所以无论应用程序在哪里,路径都是正确的.
我正努力在我的班级中进行扩展android.app.Activity.
也许类似于"从资产中获取文件路径".
Bal*_*usC 24
利用类路径.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("path/to/folder");
File file = new File(url.toURI());
// ...
Run Code Online (Sandbox Code Playgroud)
Ken*_*net 19
您在寻找应用程序的根文件夹吗?然后我会用
String path = getClass().getClassLoader().getResource(".").getPath();
Run Code Online (Sandbox Code Playgroud)
实际上"找出我在哪里".
File relativeFile = new File(getClass().getResource("/icons/forIcon.png").toURI());
myJFrame.setIconImage(tk.getImage(relativeFile.getAbsolutePath()));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
116781 次 |
| 最近记录: |