Escape result of FileLocator.resolve(url)

前端 未结 3 1916
孤独总比滥情好
孤独总比滥情好 2021-02-15 15:31

The method FileLocator.resolve(url) can be used to translate an address bundleentry://something/somewhere/x.txt to a proper file URL for /mnt/foo

3条回答
  •  一向
    一向 (楼主)
    2021-02-15 16:18

    From Vogella Blog:

    URL url;
    try {
        url = new 
        URL("platform:/plugin/de.vogella.rcp.plugin.filereader/files/test.txt");
        InputStream inputStream = url.openConnection().getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
        String inputLine;
    
    while ((inputLine = in.readLine()) != null) {
        System.out.println(inputLine);
    }
    
    in.close();
    
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    To get the URL, Following can be used:

    Bundle thisBundle = FrameworkUtil.getBundle(getClass());
    URL fileURL = thisBundle.getEntry("

    Also, one can choose the type of Stream/Reader to read image/text.

提交回复
热议问题