For the complete documentation index, see llms.txt. This page is also available as Markdown.

Property Files

Work with property files using BoxLang's fluent PropertyFile API

Introduced in v1.4.0

πŸ™‹ What are Property Files?

Property files are simple text files that store configuration data in key-value pairs. They're commonly used for application settings, environment configurations, and localization. BoxLang provides a powerful, fluent API for reading, writing, and manipulating property files with ease.

# Example property file
app.name=My Application
app.version=1.0.0
database.host=localhost
database.port=5432

🎯 Why Use BoxLang's PropertyFile Utility?

  • Fluent API: Chain operations together for clean, readable code

  • Format Preservation: Maintains comments, whitespace, and original formatting

  • Smart Parsing: Handles escaped characters, unicode, and line continuations

  • Type Safety: Built-in validation and error handling

  • Memory Efficient: Lazy loading and caching for optimal performance

  • Cross-Platform: Works consistently across different operating systems

πŸš€ Getting Started

Creating a PropertyFile Object

The main entry point is the propertyFile() BIF (Built-In Function):

If the file path doesn't exist, the PropertyFile object will be created with that path for future use when storing.

πŸ“– Reading Properties

πŸ” Getting Property Values

πŸ“Š Getting All Properties

πŸ”’ Property File Information

✏️ Writing Properties

πŸ”§ Setting Individual Properties

πŸ“ Setting Multiple Properties

πŸ—‘οΈ Removing Properties

πŸ’Ύ Saving Property Files

πŸ“ Storing to File

🎨 Formatting and Comments

πŸ’¬ Adding Comments

πŸ“ Line Width Control

πŸ”„ Advanced Operations

πŸ”€ Merging Property Files

πŸ—οΈ Creating from Existing Data

πŸ“š Common Usage Patterns

πŸ”§ Configuration Management

🌐 Internationalization (i18n)

🏭 Environment Configuration

πŸ“ Build and Deployment

πŸ” Data Export and Conversion

πŸ“„ Export Formats

πŸ”„ Format Conversion

πŸ›‘οΈ Error Handling

🚨 Exception Management

βœ… Safe Property Access

🎯 Best Practices

βœ… Do's

  • Use descriptive property names with dot notation for hierarchy

  • Provide default values for optional configuration

  • Add comments to explain complex or important settings

  • Validate required properties at application startup

  • Use environment-specific files for different deployment scenarios

  • Keep sensitive data separate and secure (passwords, API keys)

❌ Don'ts

  • Don't hardcode file paths - use relative paths or configuration

  • Don't ignore exceptions - handle file access errors gracefully

  • Don't store large binary data in property files

  • Don't forget to call store() after making changes

  • Don't mix different data types - property values are always strings

🚦 Performance Tips

🎯 Optimization Guidelines

  • Cache PropertyFile objects for frequently accessed configurations

  • Use getAsStruct() once and reuse for multiple property access

  • Minimize file I/O by batching property updates

  • Set appropriate maxLineWidth for your use case

  • Avoid unnecessary store() calls - batch your changes

πŸ”— Integration Examples

🌐 Web Application Configuration

πŸ”§ Module Configuration

πŸ“± CLI Application Settings

Property files in BoxLang provide a robust, flexible way to manage configuration data with a clean, fluent API that makes complex property file operations simple and intuitive. Whether you're building web applications, CLI tools, or enterprise systems, the PropertyFile utility adapts to your needs while maintaining data integrity and format preservation.

Last updated

Was this helpful?