Java Resource Get getResources(String archiveName)

Here you can find the source of getResources(String archiveName)

Description

get Resources

License

Open Source License

Declaration

public static File getResources(String archiveName) 

Method Source Code

//package com.java2s;
/*// w ww. j a  v  a2 s  .c om
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.io.File;

import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    public static File getResources(String archiveName) {
        String name = archiveName;

        URL url = Thread.currentThread().getContextClassLoader().getResource(name);
        if (url == null) {
            System.err.println("No resources for " + archiveName);
            return null;
        }
        try {
            File file = new File(url.toURI());
            if (!file.exists()) {
                throw new IllegalArgumentException("Could not find " + file.getAbsolutePath());
            }
            if (!file.isDirectory()) {
                throw new IllegalArgumentException(file.getAbsolutePath() + " is not a directory");
            }
            return file;

        } catch (URISyntaxException e) {
            throw new RuntimeException("Could not get file for " + url);
        }
    }
}

Related

  1. getResourceFromFile(String filename)
  2. getResourceInBundleOrFragments(Bundle bundle, String name)
  3. getResourceListing(ClassLoader cl)
  4. getResourceMessage(Locale locale, String resource, String key, Object... params)
  5. getResourceReader(Class clazz, String name, String charset)
  6. getResources(String pkgName)
  7. getResourcesFromDirectory(File resource, Pattern pattern)
  8. getResourceString(ResourceBundle rb, String key, Object param1)
  9. getResourceString(String key)