Skip to content

YuriiJavaDev/JavaBasics_Task_193_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Digital Diary Reader (JavaBasics_Task_193_V0.1)

📖 Description

This project focuses on the retrieval aspect of file management. It demonstrates how to use the java.nio.file package to read the contents of an existing text file. This is a critical skill for any application that needs to load settings, user data, or saved logs.

📋 Requirements Compliance

  • Task: Read the entire content of note.txt.
  • Method: Use Files.readString(Path) for efficient reading.
  • Verification: Output the retrieved string to the console.
  • Goal: Master basic file input operations using Java NIO.

🚀 Architectural Stack

  • Java 8+ (NIO.2)

🏗️ Implementation Details

The application assumes the file note.txt exists in the root directory.

  • Paths.get("note.txt") creates a reference to the file location.
  • Files.readString(path) reads all characters from the file into a single String.
  • Error handling is implemented via a try-catch block to manage IOException, such as if the file is missing.

📋 Expected result

Reading from diary...
Content: Today is a great day!

💻 Code Example

Project Structure:

├── note.txt
└── src src/com/yurii/pavlenko/
                        └── Solution.java

Code

package com.yurii.pavlenko;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Solution {

    public static void main(String[] args) {

        Path notePath = Paths.get("note.txt");

        try {
            System.out.println("Reading from diary...");
            String content = Files.readString(notePath);
            System.out.println("Content: " + content);

        } catch (IOException e) {
            System.out.println("Error: Could not read the file. " + e.getMessage());
        }
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_193_V0.1 Implementing file reading functionality using modern Java NIO Files and Path API to display diary notes. 280226_0825

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages