search

Home  >  Q&A  >  body text

web工程中,java类中如何获取图片资源的路径?

如图:

我想要在ZXingCode类中,加载下面的image文件夹下的图片,路径怎么写?
File file = new File(filePath);
试着放了几个地方都不知道怎么写,不要本地绝对路径,要项目路径

PHP中文网PHP中文网2817 days ago334

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-18 10:18:54

    public static void main(String[] args){
        URL url = ClassLoader.getSystemResource("config/image/***.jpg");
        File file = new File(url.getPath());
        System.out.println(file.exists());
    }

    More references here

    reply
    0
  • PHPz

    PHPz2017-04-18 10:18:54

    Why do you have to ask questions when you can get the answer from any search engine?

    reply
    0
  • Cancelreply