/
siman_coder
/
TaskExtrakt
Обзор
Документация
Войти
/
siman_coder
/
TaskExtrakt
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
78 строк
3 KB
siman_coder
Create: Main.java
26 июн 2026, 11:25
Верифицирован
26 июн 2026, 11:25
afdb113
Код
Авторство
О чём код?
import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { public static void main(String[] args) { String savegamesPath = "D:/Games/savegames"; String zipPath = savegamesPath + "/saves.zip"; System.out.println("=== ЗАДАЧА 3: ЗАГРУЗКА ===\n"); System.out.println("--- РАЗАРХИВАЦИЯ ---"); openZip(zipPath, savegamesPath); System.out.println("\n--- ЗАГРУЗКА СОХРАНЕНИЯ ---"); String saveFile = savegamesPath + "/save2.dat"; GameProgress progress = openProgress(saveFile); if (progress != null) { System.out.println("\n--- СОСТОЯНИЕ ИГРЫ ---"); System.out.println(progress); } } public static void openZip(String zipPath, String extractPath) { byte[] buffer = new byte[1024]; try (FileInputStream fis = new FileInputStream(zipPath); ZipInputStream zis = new ZipInputStream(fis)) { ZipEntry zipEntry; while ((zipEntry = zis.getNextEntry()) != null) { String fileName = zipEntry.getName(); File newFile = new File(extractPath + File.separator + fileName); newFile.getParentFile().mkdirs(); try (FileOutputStream fos = new FileOutputStream(newFile)) { int length; while ((length = zis.read(buffer)) > 0) { fos.write(buffer, 0, length); } } System.out.println(" ✓ Извлечен: " + fileName); zis.closeEntry(); } System.out.println("✅ Распаковка завершена"); } catch (IOException e) { System.err.println("❌ ОШИБКА: " + e.getMessage()); } } public static GameProgress openProgress(String filePath) { try (FileInputStream fis = new FileInputStream(filePath); ObjectInputStream ois = new ObjectInputStream(fis)) { Object obj = ois.readObject(); if (obj instanceof GameProgress) { System.out.println("✅ Загружено: " + new File(filePath).getName()); return (GameProgress) obj; } } catch (FileNotFoundException e) { System.err.println("❌ Файл не найден: " + filePath); } catch (IOException e) { System.err.println("❌ Ошибка ввода-вывода: " + e.getMessage()); } catch (ClassNotFoundException e) { System.err.println("❌ Класс не найден: " + e.getMessage()); } return null; } }