Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmail.ua.org.vinogradoff;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class Task1level1 {
- public static void main(String[] args) {
- saveTextToFile(enterText());
- }
- public static String enterText() {
- System.out.println("Введите текст, по окончании с новой строки введите \"Exit\"");
- StringBuilder sb = new StringBuilder();
- Scanner sc = new Scanner(System.in);
- for (;;) {
- String tmp = sc.nextLine();
- if (tmp.equalsIgnoreCase("exit")) break;
- sb.append(tmp);
- sb.append(System.lineSeparator());
- }
- return sb.toString();
- }
- public static void saveTextToFile(String text) {
- System.out.println("Введите имя файла для сохранения");
- Scanner sc = new Scanner(System.in);
- File file = new File(sc.nextLine());
- try (PrintWriter pw = new PrintWriter(file)) {
- pw.println(text);
- System.out.println("Все");
- } catch (IOException e) {
- System.out.println(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment