Commit 3bdbe95
committed
feat(TokenizeFileDemo): add program to tokenize file contents using StringTokenizer
What
- Added TokenizeFileDemo in Package1.
- Reads raw text data from a file.
- Uses `StringTokenizer` with delimiters `"= "` to split tokens.
- Prints each extracted token line by line.
Why
- Demonstrates how to parse configuration-style text files where data is separated by `=` or whitespace.
- Useful for simple parsing tasks without external libraries.
- Helps in breaking raw file input into manageable tokens for processing.
How
- Opened a file using `FileInputStream`.
- Read available bytes into a byte array and converted into a String.
- Created `StringTokenizer` with delimiters `= ` (equals sign and space).
- Iterated with `hasMoreTokens()` and `nextToken()` to print tokens one by one.
Logic
- `FileInputStream` loads file bytes into memory.
- `new String(b)` reconstructs the file’s textual content.
- `StringTokenizer` splits the string wherever it finds `=` or space.
- Iteration collects each token until no more remain.
Real-life applications
- Parsing `.properties` or configuration files.
- Splitting command-line input or key-value data.
- Quick preprocessing of logs, metadata, or user input.
Summary
- TokenizeFileDemo reads a text file and tokenizes its content.
- Splits data using delimiters `= ` into key/value-like tokens.
- Demonstrates file I/O + string parsing in Java.
Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>1 parent 8706fc4 commit 3bdbe95
2 files changed
Lines changed: 6 additions & 8 deletions
Lines changed: 6 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | | - | |
| 18 | + | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
25 | | - | |
| 23 | + | |
0 commit comments