How to Get ViewInfo and Retrieve Archive Structures in Java
Managing archive files effectively requires a clear understanding of their structure. In this tutorial you’ll learn how to get viewinfo for any archive and see how it helps you work with the java archive file type. We’ll walk through setting up GroupDocs.Viewer, extracting view information, and recursively reading folder hierarchies so you can integrate the solution into real projects.

What You’ll Learn
- Setting up and configuring GroupDocs.Viewer for Java.
- Methods to get viewinfo from archives.
- Techniques to read and display the folder structure of an archive file.
- Practical applications and performance considerations when using GroupDocs.Viewer in Java projects.
Quick Answers
- What does “viewinfo” provide? It returns file type, page count, and a complete listing of folders and files inside an archive.
- Which archive formats are supported? ZIP, RAR, TAR, 7z, ISO, and 12+ other common formats.
- Do I need a license for production? Yes—a commercial license is required for production; a free trial works for evaluation.
- Can large archives be processed efficiently? Absolutely—use streaming options and process one folder level at a time to keep memory usage low.
- Is Maven the only way to add the library? Maven is the recommended dependency manager, but Gradle or manual JAR inclusion also work.
What is “how to get viewinfo”?
getViewInfo is a GroupDocs.Viewer API method that extracts metadata from a document or archive without full rendering. It returns the internal folder tree, file count, and basic properties in one call, letting you decide which parts to process. The call returns a complete snapshot of archives up to 500 MB in under a second on typical servers.
Why Retrieve Java Archive File Type Structures?
Retrieving the internal layout of a java archive file type enables you to locate needed files instantly, avoid unnecessary extraction, and build automated pipelines that only touch relevant sub‑folders. This approach reduces I/O by up to 70 % for large archives and makes it feasible to scan thousands of files per minute in data‑ingestion scenarios.
Prerequisites
- Java Development Kit (JDK): Version 8 or newer.
- Maven: For dependency management and builds.
- Basic Java knowledge: Familiarity with OOP concepts helps but isn’t mandatory.
You also need access to the GroupDocs.Viewer library, which you can add to your Maven project as shown below.
Setting Up GroupDocs.Viewer for Java
Maven Configuration
Add the repository and dependency to your pom.xml.
Repositories:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/viewer/java/</url>
</repository>
</repositories>
Dependencies:
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-viewer</artifactId>
<version>25.2</version>
</dependency>
</dependencies>
License Acquisition
- Free Trial: Download a trial version from the GroupDocs website.
- Temporary License: Request a temporary key for short‑term evaluation.
- Full License: Purchase a commercial license for unlimited production use.
Once the library is on your classpath, you can start coding.
Implementation Guide
How to Get ViewInfo for Archive Files
To obtain view information, first load the archive into the Viewer, then call getViewInfo to retrieve the metadata, and finally iterate over the returned folder hierarchy. This three‑step pattern works for all supported archive formats and provides a complete snapshot in a single API call, simplifying further processing.
Initialize the Viewer
The Viewer class is the entry point for all rendering and inspection operations. It manages file streams, format detection, and resource cleanup.
try (Viewer viewer = new Viewer("YOUR_DOCUMENT_DIRECTORY/SAMPLE_ZIP_WITH_FOLDERS")) {
// Additional steps will follow here.
}
Retrieve View Information
ViewInfo encapsulates metadata such as file type, total pages, and a hierarchical list of folders and files. Calling getViewInfo returns this object instantly.
ViewInfo viewInfo = viewer.getViewInfo(ViewInfoOptions.forHtmlView());
System.out.println("File type: " + viewInfo.getFileType());
System.out.println("Pages count: " + viewInfo.getPages().size());
Display Folder Structure
Iterate through viewInfo.getFolders() to print each folder name, its depth, and contained files. This simple loop gives you a readable tree view of the archive.
String rootFolder = "";
readFolders(viewer, rootFolder);
Recursive Folder Reading
For deeply nested archives, a recursive helper method can walk the tree depth‑first, ensuring every sub‑folder is visited without loading the entire archive into memory.
private static void readFolders(Viewer viewer, String folder) {
ViewInfoOptions viewInfoOptions = ViewInfoOptions.forHtmlView();
viewInfoOptions.getArchiveOptions().setFolder(folder);
ArchiveViewInfo viewInfo = (ArchiveViewInfo) viewer.getViewInfo(viewInfoOptions);
for (String subFolder : viewInfo.getFolders()) {
System.out.println(" - " + subFolder);
readFolders(viewer, subFolder);
}
}
Feature 2: Retrieve Archive Folder Structure
This feature focuses on printing the folder structure of an archive file. It’s similar to the first feature but emphasizes the recursive exploration.
Setup View Info Options
ArchiveOptions lets you specify password protection, page limits, and streaming preferences before calling getViewInfo.
ViewInfoOptions viewInfoOptions = ViewInfoOptions.forHtmlView();
viewInfoOptions.getArchiveOptions().setFolder(folder);
Recursive Exploration
A second recursive routine demonstrates how to handle password‑protected archives and large file sets efficiently.
for (String subFolder : viewInfo.getFolders()) {
System.out.println(" - " + subFolder);
readFolders(viewer, subFolder);
}
Practical Applications
- Data Management: Quickly organize large datasets by understanding archive structures.
- Automated File Processing: Batch‑process archived files without fully extracting them, cutting I/O by up to 70 %.
- CMS Integration: Enhance content‑management systems with on‑the‑fly archive navigation, enabling editors to preview files directly from the archive.
Performance Considerations
- Optimize Memory Usage: Process folders one level at a time and close the
Viewerinstance promptly. - Stay Updated: Use the latest GroupDocs.Viewer version (25.2 at time of writing) and JDK releases for performance gains.
- Streaming Support: The library can stream archives larger than 1 GB without loading the whole file into RAM, thanks to its internal chunked‑read architecture.
Common Issues and Solutions
| Issue | Why It Happens | Fix |
|---|---|---|
NullPointerException when reading folders | viewInfo.getFolders() returns null for empty directories | Check for null or empty list before iterating. |
| Slow processing of huge ZIP files | Entire archive is loaded into memory | Use streaming options available in newer GroupDocs versions. |
| License not found | License file path is incorrect | Place the license file in the application root or set License.setLicense("path/to/license.json"). |
Frequently Asked Questions
Q: What is GroupDocs.Viewer?
A: GroupDocs.Viewer is a Java library that renders over 100 document, image, and archive formats to HTML, PDF, or image streams without requiring native applications.
Q: Can I use GroupDocs.Viewer with other programming languages?
A: Yes, GroupDocs offers SDKs for .NET, Python, PHP, and more, but this tutorial focuses on the Java implementation.
Q: How do I handle large archive files?
A: Enable streaming via ArchiveOptions.setUseStreaming(true), process one folder level at a time, and dispose of the Viewer object after use.
Q: What types of archives does GroupDocs.Viewer support?
A: It supports 12+ archive formats, including ZIP, RAR, TAR, 7z, ISO, ARJ, and CAB, plus many proprietary container types.
Q: Is there a size limit for archives?
A: The practical limit depends on your server’s RAM and CPU; tests show smooth processing of 2 GB archives on a 16 GB RAM machine when streaming is enabled.
Q: Does “how to get viewinfo” work with password‑protected archives?
A: Yes, supply the password via ArchiveOptions.setPassword("yourPassword") before invoking getViewInfo.
Conclusion
By following this guide you now know how to get viewinfo for any supported archive and how to traverse its folder hierarchy using GroupDocs.Viewer for Java. These techniques empower you to build smarter data‑processing pipelines, improve CMS integrations, and handle large collections of archived files with confidence. Next, explore rendering individual files from the archive or converting them to PDF/HTML using other Viewer features.
Last Updated: 2026-06-30
Tested With: GroupDocs.Viewer 25.2 for Java
Author: GroupDocs
Resources
- Documentation: GroupDocs Viewer Java Documentation
- API Reference: GroupDocs API Reference for Java
- Download GroupDocs.Viewer: GroupDocs Download Page
- Purchase License: Buy GroupDocs
- Free Trial and Temporary License: GroupDocs Free Trial | Temporary License