Skip to content

This Java application generates Lorem Ipsum text, reads and processes text files word by word, showcasing file I/O, text processing, and iterator pattern implementation.

Notifications You must be signed in to change notification settings

lfmramos/tool-word-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lorem Ipsum Generator & Word Reader

A Java application that generates Lorem Ipsum text and provides functionality to read and process text files word by word. This project demonstrates file I/O operations, text processing, and iterator pattern implementation in Java.

Features

  • Random Lorem Ipsum text generation
  • Configurable paragraph length
  • File writing capabilities
  • Word-by-word text file reading
  • Special character filtering
  • Iterator implementation for easy word traversal

Components

LoremIpsum Generator

  • Generates random Lorem Ipsum text
  • Customizable word count (50-100 words by default)
  • Uses a predefined dictionary of Latin words
  • Produces properly formatted paragraphs with punctuation

WordReader

  • Reads text files word by word
  • Implements Iterable<String> interface
  • Filters non-alphabetic characters
  • Efficient buffered reading
  • Proper resource management

Usage

Generating Lorem Ipsum Text

LoremIpsum lorem = new LoremIpsum();
String paragraph = lorem.getParagraph(); // Generates one paragraph

Reading Words from File

try {
    WordReader wordReader = new WordReader("path/to/your/file.txt");
    for (String word : wordReader) {
        System.out.println(word);
    }
} catch (IOException ex) {
    System.out.println(ex.getMessage());
}

Technical Details

File Structure

project-root/
├── src/
│   └── io/codeforall/fanstatics/
│       ├── Main.java
│       ├── LoremIpsum.java
│       └── WordReader.java
└── rsc/
    └── lorem_ipsum.txt

LoremIpsum Class

  • Uses Random for word selection
  • Maintains a static word dictionary
  • Implements paragraph formatting
  • Configurable word count range

WordReader Class

  • Implements Iterable<String>
  • Uses BufferedReader for efficient file reading
  • Handles file I/O exceptions
  • Text cleaning and processing
  • Memory-efficient word iteration

Implementation Details

Text Generation Process

  1. Random word count selection (50-100 words)
  2. Word selection from predefined dictionary
  3. Proper spacing and punctuation
  4. Final formatting and period addition

Text Reading Process

  1. File opening with error handling
  2. Buffered reading of text content
  3. Special character removal
  4. Word splitting and storage
  5. Iterator implementation for word access

Getting Started

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Java IDE (recommended: IntelliJ IDEA or Eclipse)

Running the Application

  1. Compile the Java files:
javac io/codeforall/fanstatics/*.java
  1. Run the main class:
java io.codeforall.fanstatics.Main

Directory Setup

Ensure the rsc directory exists in your project root:

mkdir rsc

Error Handling

The application includes robust error handling for:

  • File not found scenarios
  • I/O exceptions
  • Resource management
  • Proper file closing

Future Enhancements

Potential improvements could include:

  1. Multiple paragraph generation
  2. Different text styles
  3. Custom word dictionary support
  4. HTML/markdown output formatting
  5. Statistical analysis of generated text
  6. Command-line arguments support
  7. Configuration file support

Best Practices Implemented

  • Resource management using try-with-resources
  • Proper exception handling
  • Interface-based design
  • Clean code principles
  • Single Responsibility Principle
  • Iterator Pattern implementation

Contributing

Feel free to submit issues and enhancement requests!

About

This Java application generates Lorem Ipsum text, reads and processes text files word by word, showcasing file I/O, text processing, and iterator pattern implementation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages