FileUtils

File related utility methods. For example, to get the filename or extension. 

Methods

getFileName

Description:

MethodReturn valuesDescription

getFileName(String file)

String

Returns the name of the file without the extension.

file: The full name of the file.

Example:

package com.openkm;

import java.io.File;

import com.openkm.util.FileUtils;
import com.openkm.util.PathUtils;

public class Test {
	public static void main(String[] args) {
		try {
			File file = new File("/home/openkm/test.png");
			String docName = PathUtils.getName(file.getPath());
			String baseName = FileUtils.getFileName(docName);
			System.out.println(baseName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

getFileExtension

Description:

MethodReturn valuesDescription

getFileExtension(String file)

String

Returns the filename extension.

file: The full name of the file.

Example:

package com.openkm;

import java.io.File;

import com.openkm.util.FileUtils;
import com.openkm.util.PathUtils;

public class Test {
	public static void main(String[] args) {
		try {
			File file = new File("/home/openkm/test.png");
			String docName = PathUtils.getName(file.getPath());
			String extension = FileUtils.getFileExtension(docName);
			System.out.println(extension);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}