get Resource As File - Java Internationalization

Java examples for Internationalization:Resource File

Description

get Resource As File

Demo Code


import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URISyntaxException;
import java.net.URL;

public class Main{
    public static void main(String[] argv) throws Exception{
        String file = "java2s.com";
        System.out.println(getResourceAsFile(file));
    }//from   w w  w  . j av a 2  s . co m
    private static File getResourceAsFile(String file) {
        URL url = Main.class
                .getResource(file);
        try {
            return new File(url.toURI());
        } catch (URISyntaxException e) {
            return new File(url.getPath());
        }
    }
}

Related Tutorials