⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileutils.java

📁 一个用struts tiles的在线影院web系统
💻 JAVA
字号:
package com.blue.web.common.util;

import java.io.File;

/**
 * 
 * @author Lucifer
 *
 */
public final class FileUtils {
	// 
	public static final char DirectorySeparatorChar		= '\\';
	public static final char AltDirectorySeparatorChar	= '/';
	public static final char VolumeSeparatorChar			= ':';

	/**
	 * This class cannot be instantiated.
	 *
	 */
	private FileUtils() {
	}

	public static String getFileName(String path) {
		if (path != null) {
			int length = path.length();
			int index = length;
			while (--index >= 0) {
				char ch = path.charAt(index);
				if (((ch == FileUtils.DirectorySeparatorChar) || (ch == FileUtils.AltDirectorySeparatorChar))
						|| (ch == FileUtils.VolumeSeparatorChar)) {
					return path.substring(index + 1, length);
				}
			}
		}
		return path;
	}

	public static final String getFileExtension(File file) {
		return getFileExtension(file.getName());
	}

	public static final String getFileExtension(String path) {
		String extension = "";
		int iIndex = path.lastIndexOf(".");
		if(iIndex > 0)
			extension = path.substring(iIndex + 1);
		return extension;
	}

	/**
	 * Get tne name of a file without the extension.
	 * @param file
	 * @return
	 */
	public static final String getFileNameWithoutExtension(File file) {
		return getFileNameWithoutExtension(file.getName());
	}

	/**
	 * Get a file name without the extension.
	 * @param path The name of the file
	 * @return
	 */
	public static final String getFileNameWithoutExtension(String path) {
		String filename = getFileName(path);
		int index = filename.lastIndexOf(".");
		if(index > 0)
			filename = filename.substring(0, index);
		return filename;
	}
	
	public static final String getPathWithoutFileName(String path) {
		int index = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
		if (index < 0)
			return path;
		return path.substring(0, index);
	}
}

⌨️ 快捷键说明

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