filepath.java

来自「jsp 应用开发技术光盘 是《jsp应用开发技术》这本书的源代码」· Java 代码 · 共 34 行

JAVA
34
字号
package ch14.binaryFile;

import java.net.URL;

public class FilePath {
	
	private static String classPath = getClassPath();
	
	private FilePath() {
		
	}
	
	private static String getClassPath() {
		Class c = FilePath.class;
		ClassLoader loader = c.getClassLoader();		
		String name = c.getName();
		name = name.replace('.', '/') + ".class";
		URL url = loader.getResource(name);
		String path = url.getFile();
		path = path.substring(1);		
		path = path.replace('/','\\');
		int index = path.lastIndexOf("\\");
		path = path.substring(0, index);
		path = path.replaceAll("%20"," ");
		return path;
	}
	
	public static String getFilePath(String fileName) {
		System.out.println("File Path:" + classPath + fileName);
		return classPath + fileName;
	}
	
}

⌨️ 快捷键说明

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