How can I get relative path of the folders in my android project?

前端 未结 8 1664
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 19:16

How can I get the relative path of the folders in my project using code?

I\'ve created a new folder in my project and I want its relative path so no matter where the

相关标签:
8条回答
  • 2020-12-08 20:10
    File relativeFile = new File(getClass().getResource("/icons/forIcon.png").toURI());
    myJFrame.setIconImage(tk.getImage(relativeFile.getAbsolutePath()));
    
    0 讨论(0)
  • 2020-12-08 20:11

    Make use of the classpath.

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL url = classLoader.getResource("path/to/folder");
    File file = new File(url.toURI());
    // ...
    
    0 讨论(0)
提交回复
热议问题