Area 03 · File handling
Log file summary
Count the INFO, WARN and ERROR lines in a log file, flag the malformed lines, and save the summary to a new file.
- Spec no.
- HO-05
- Level
- Warm-up
- Time box
- 45 min
- Reference
- Java · C#
- Grading
- Self-assessed · rubric is ours, not DICT's
01 Coverage
| Area | Sub-skills practised | Role |
|---|---|---|
| 01 Data manipulation | String, Validation | Also |
| 03 File handling | Input/output validation, Read, Create | Primary |
Sign up to start coding practice
Read the task freely. An account is required before editing and running a solution. Code runs also need an internet connection.
Sign up or sign in02 Requirements
- Read a file name from standard input. If it does not exist print File not found: <name> and stop.
- A valid line is yyyy-mm-dd, a space, INFO, WARN or ERROR, a space, then a message. Anything else is malformed.
- Count each level. Remember the line numbers (from 1) of malformed lines.
- Create or overwrite summary.txt with the four summary lines, and print the same lines.
- Close every file, even on errors.
03 Input and output
- One line: the log file name (app.log in the sample, given below)
- INFO: n, WARN: n, ERROR: n
- Malformed: n (line a, b)
- summary.txt with the same content
app.logINFO: 2
WARN: 1
ERROR: 1
Malformed: 2 (line 3, 6)2026-03-01 INFO started
2026-03-01 WARN disk 85% full
bad line
2026-03-02 ERROR cannot open file
2026-03-02 INFO stopped
2026-3-2 INFO wrong dateINFO: 2
WARN: 1
ERROR: 1
Malformed: 2 (line 3, 6)Match the sample exactly first, then write at least two test inputs of your own.
04 Edge cases to test
- A missing file
- An empty file (all counts 0, Malformed: 0)
- A date without leading zeros (2026-3-2)
- A level in lower case
05 Starter outline and hints
name = readLineopen reader (catch not found)for each line: match pattern → count level, else record line nowrite summary.txt; print the same lines
Hint 1
A regular expression such as ^\d{4}-\d{2}-\d{2} (INFO|WARN|ERROR) \S.*$ checks the whole line at once.
06 Practice rubric
| Criterion | Sub-skills | Look for | Pts |
|---|---|---|---|
| Reading | Read | Line-by-line read with a reader closed by try-with-resources / using. | 25 |
| Validation | Input/output validationValidation | Malformed lines detected with exact line numbers; missing file handled. | 30 |
| Writing | Create | summary.txt created or overwritten with the right content. | 25 |
| String handling | String | Pattern or split logic that is easy to read. | 20 |
| Total | 100 | ||
Our own weighting for practice. It is not the DICT scoring scheme.
07 Self-check
Tick only what you have verified by running your own program.
Loading saved checks…
08 Reference solution
Both versions compiled and reproduced the sample output on Java 21 and .NET 8 when this site was built. Reference solutions are in Java and C#. The 2023 FAQ copy also lists C, C++ and Visual Basic 6.0 / .NET; the same structure carries over, but you will need your language's own file and database APIs.
Try the whole brief first. The reference is one correct approach, not the only one, and reading it early removes most of the practice value.
09 Exam-day habits
- Work without internet search to simulate exam conditions.
- Type the sample input yourself and compare your output line by line before you look at the reference.