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
📋 Table of Contents
🚀 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?
