Java Resource Load getResourceAbsolutePath(String pluginId, String... path)

Here you can find the source of getResourceAbsolutePath(String pluginId, String... path)

Description

Provide bundle resource absolute path

License

Open Source License

Parameter

Parameter Description
pluginId - plugin id
path - resource relative path

Return

resource absolute path

Declaration

public static String getResourceAbsolutePath(String pluginId, String... path) 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;

public class Main {
    /**//from www  .j  a v  a2  s  .  c  o m
     * Provide bundle resource absolute path
     * 
     * @param pluginId
     *            - plugin id
     * @param path
     *            - resource relative path
     * @return resource absolute path
     */
    public static String getResourceAbsolutePath(String pluginId, String... path) {

        // Construct path
        StringBuilder builder = new StringBuilder();
        for (String fragment : path) {
            builder.append("/" + fragment);
        }

        String filePath = "";
        try {
            filePath = FileLocator.toFileURL(Platform.getBundle(pluginId).getEntry("/")).getFile() + "resources"
                    + builder.toString();
            File file = new File(filePath);
            if (!file.isFile()) {
                filePath = FileLocator.toFileURL(Platform.getBundle(pluginId).getEntry("/")).getFile()
                        + builder.toString();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        return filePath;
    }
}

Related

  1. getResource(String fileName, int type)
  2. getResource(String name)
  3. getResource(String path)
  4. getResource(String propertiesPath)
  5. getResource(String uri)
  6. getResourceAsBufferedReader(Class clazz, String resourceName)
  7. getResourceAsByteArray(Object context, String resourceName)
  8. getResourceAsByteArray(String url)
  9. getResourceAsBytes(Class cl, String resname)