zoukankan      html  css  js  c++  java
  • URL to load resources from the classpath in Java

    In Java, you can load all kinds of resources using the same API but with different URL protocols:

    file:///tmp.txt
    http://127.0.0.1:8080/a.properties
    jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class

    This nicely decouples the actual loading of the resource from the application that needs the resource, and since a URL is just a String, resource loading is also very easily configurable.

    Is there a protocol to load resources using the current classloader? This is similar to the Jar protocol, except that I do not need to know which jar file or class folder the resource is coming from.

    I can do that using Class.getResourceAsStream("a.xml"), of course, but that would require me to use a different API, and hence changes to existing code. I want to be able to use this in all places where I can specify a URL for the resource already, by just updating a property file.

  • 相关阅读:
    随记(二)--是否能打开手机某个应用
    asp.net 登陆后在ashx处理程序中获取不到Session
    Highcharts Pie 饼图提示标签IE下重叠解决方法,及json数据绑定方法
    怎样用ZBrush对模型进行渲染(二)
    怎样用ZBrush对模型进行渲染
    ZBrush中该如何调节多个SubTool
    如何用ZBrush快速绘制身体
    MIDI信息为什么不能通过FL Studio输出
    怎样制作FL Studio步进音序器中的节奏
    不同材质怎么通过ZBrush赋予同一个模型上
  • 原文地址:https://www.cnblogs.com/sidesky/p/10563935.html
Copyright © 2011-2022 走看看