/
Letta21
/
Letta
Обзор
Документация
Войти
/
Letta21
/
Letta
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
FileDirCreate
63 строки
2 KB
Letta21
create FileDirCreate
15 дек 2025, 07:55
15 дек 2025, 07:55
210135f
Код
Авторство
О чём код?
import java.io.File; import java.io.FileWriter; import java.io.IOException; public class GameInstaller { private static StringBuilder log = new StringBuilder(); public static void main(String[] args) { String rootPath = "C:\\Users\\Letta\\Desktop\\Games"; createDirectory(rootPath + "/src"); createDirectory(rootPath + "/res"); createDirectory(rootPath + "/savegames"); createDirectory(rootPath + "/temp"); createDirectory(rootPath + "/src/main"); createDirectory(rootPath + "/src/test"); // Создаем файлы в src/main createFile(rootPath + "/src/main/Main.java"); createFile(rootPath + "/src/main/Utils.java"); // Создаем директории в res createDirectory(rootPath + "/res/drawables"); createDirectory(rootPath + "/res/vectors"); createDirectory(rootPath + "/res/icons"); // Создаем файл temp.txt в директории temp createFile(rootPath + "/temp/temp.txt"); try (FileWriter writer = new FileWriter(rootPath + "/temp/temp.txt")) { writer.write(log.toString()); System.out.println("Установка завершена. Лог записан в temp.txt"); } catch (IOException e) { System.out.println("Ошибка при записи лога: " + e.getMessage()); } System.out.println(log); } private static void createDirectory(String path) { File dir = new File(path); if (dir.mkdir()) { log.append("Каталог создан: ").append(path).append("\n"); } else { log.append("Каталог НЕ создан (возможно, уже существует): ") .append(path).append("\n"); } } private static void createFile(String path) { File file = new File(path); try { if (file.createNewFile()) { log.append("Файл создан: ").append(path).append("\n"); } else { log.append("Файл НЕ создан: (возможно, уже существует): ").append(path).append("\n"); } } catch (IOException e) { log.append("Ошибка при создании файла ") .append(path).append(": ").append(e.getMessage()).append("\n"); } } }