loader.java

来自「plugin for eclipse」· Java 代码 · 共 37 行

JAVA
37
字号
package isis.commons.fs;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Loader {
	/**
	 * Get an input stream on a file on the classpath.
	 * @param name file name.
	 * @return the input stream
	 * @throws IOException
	 */
	public static InputStream getStream(String name) throws FileNotFoundException {
		InputStream is = null;
		
		// try with the current thread's classloader
		is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
		if(is!=null) return is;
		
		// try with the classloader that loaded this class
		is = SearchPath.class.getClassLoader().getResourceAsStream(name);
		if(is!=null) return is;
		
		// try with the system classloader
		is = ClassLoader.getSystemClassLoader().getResourceAsStream(name);
		if(is!=null) return is;
		
		throw new FileNotFoundException("Could open resource stream for search path list "+name);
	}		

	/**
	 * Private constructor.
	 */
	private Loader() {}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?