Loads a file from the resource directory. - Java java.util

Java examples for java.util:Properties File

Description

Loads a file from the resource directory.

Demo Code


//package com.java2s;

import java.io.File;

public class Main {
    public static void main(String[] argv) throws Exception {
        String filename = "java2s.com";
        System.out.println(loadFile(filename));
    }/*from   www . j  av  a2  s . co  m*/

    private static String resources = "";
    private static ClassLoader loader;

    /**
     * Loads a file from the resource directory.
     * 
     * @param filename
     *        => The name of the file in the resource directory.
     */
    public static File loadFile(String filename) throws Exception {
        return new File(loader.getResource(resources + filename).getFile());
    }
}

Related Tutorials