Java Resource File getFileByResources(String fileName, Class clazz)

Here you can find the source of getFileByResources(String fileName, Class clazz)

Description

get File By Resources

License

Apache License

Declaration

public static File getFileByResources(String fileName, Class clazz) throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/**/* w ww .jav  a 2s  .  c  o  m*/
 * Copyright 2007 The European Bioinformatics Institute, and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Main {
    public static File getFileByResources(String fileName, Class clazz) throws UnsupportedEncodingException {
        String strFile = clazz.getResource(fileName).getFile();
        return new File(URLDecoder.decode(strFile, "utf-8"));
    }
}

Related

  1. getFile(Class clazz, String resource)
  2. getFile(Class resourceClass, String fileName)
  3. getFile(Class cls, String resource)
  4. getFile(String resource)
  5. getFile(String resourceOrFile, Class cls, boolean deleteTmpOnExit)
  6. getFileFromRelativeResource(final Class type, final String relativeResourceName)
  7. getFileFromSystemResources(String fileName)
  8. getFilename(Class clazz, String resource)
  9. getFileName(final Object resource)