Determine the file type

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

On this page

A file type is a standard way that information is encoded for storage in a computer file. For example, Microsoft Word (.docx) and Adobe PDF (.pdf) are two different file types.

Using GroupDocs.Viewer for Java, you can determine the file type using the file extension.

To determine the file type from the file extension, call the fromExtension() method of FileType.

The following code snippet shows how to determine a file type using the file extension:

import com.groupdocs.viewer.FileType;
// ...

String extension = ".docx";
FileType fileType = FileType.fromExtension(extension);

System.out.println("\nExtension " + extension + "; File type: " + fileType);

The following image shows a sample console output:

On this page