Created
May 22, 2025 06:33
-
-
Save untainsYD/0fd8f5629166a65bef5b5af5464fef60 to your computer and use it in GitHub Desktop.
Laboratory 5, Task 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package lab5; | |
| import lab5.fileio.TramStopWithTextFile; | |
| import lab5.fileio.TramStopWithBinaryFile; | |
| import java.io.File; | |
| import java.time.LocalDateTime; | |
| import java.time.format.DateTimeFormatter; | |
| /** | |
| * Демонстрація роботи з файлами для трамвайних зупинок. | |
| * Показує використання як текстових, так і бінарних файлів. | |
| */ | |
| public class Task1 { | |
| private static final String OUTPUT_DIR = "results/" + | |
| LocalDateTime.now().format( | |
| DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss") | |
| ) + "/"; | |
| public static void main(String[] args) { | |
| // Створення папки results з timestamp, якщо не існує | |
| File resultsDir = new File(OUTPUT_DIR); | |
| if (!resultsDir.exists()) { | |
| resultsDir.mkdirs(); | |
| System.out.println("Створено папку для результатів: " + OUTPUT_DIR); | |
| } | |
| System.out.println("====== Лабораторна робота №5 - Завдання 1 ======"); | |
| System.out.println("Демонстрація роботи з файлами для трамвайних зупинок"); | |
| System.out.println("Результати будуть збережені у: " + OUTPUT_DIR + "\n"); | |
| // Демонстрація роботи з текстовими файлами | |
| System.out.println("=================== РОБОТА З ТЕКСТОВИМИ ФАЙЛАМИ ==================="); | |
| TramStopWithTextFile textFileStop = new TramStopWithTextFile(); | |
| textFileStop.demonstrateFileOperations( | |
| OUTPUT_DIR + "tramstop_source.txt", | |
| OUTPUT_DIR + "tramstop_sorted_by_passengers.txt", | |
| OUTPUT_DIR + "tramstop_sorted_by_comments.txt" | |
| ); | |
| System.out.println("\n\n=================== РОБОТА З БІНАРНИМИ ФАЙЛАМИ ==================="); | |
| TramStopWithBinaryFile binaryFileStop = new TramStopWithBinaryFile(); | |
| binaryFileStop.demonstrateFileOperations( | |
| OUTPUT_DIR + "tramstop_source.dat", | |
| OUTPUT_DIR + "tramstop_sorted_by_passengers.dat", | |
| OUTPUT_DIR + "tramstop_sorted_by_comments.dat" | |
| ); | |
| System.out.println("\n====== Завершення демонстрації ======"); | |
| System.out.println("Усі результати збережено у папці: " + OUTPUT_DIR); | |
| // Виведення списку створених файлів | |
| File[] files = resultsDir.listFiles(); | |
| if (files != null && files.length > 0) { | |
| System.out.println("\nСтворені файли:"); | |
| for (File file : files) { | |
| System.out.println(" - " + file.getName()); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment