getResourceAsStream() doesn't see resource

前端 未结 2 1105
既然无缘
既然无缘 2021-01-22 12:50

I want to unpack resources from my jar file. The structure of jar looks like this:

my.jar
    META-INF
    resources
        my.exe
        my.dll
    my
                


        
相关标签:
2条回答
  • 2021-01-22 13:07

    Delete the leading slash, getResourceAsStream will use the absolute path if the first character is a slash.

    0 讨论(0)
  • 2021-01-22 13:12

    You seem to be writing Java... Not sure if this will get you round your problem, but the above could be written in Groovy as:

    this.getClass().getResource( '/resources/my.exe' ).withInputStream { ris ->
      new File( destDir ).withOutputStream { fos ->
        fos << ris
      }
    }
    
    0 讨论(0)
提交回复
热议问题