-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotepad
More file actions
42 lines (33 loc) · 1 KB
/
Notepad
File metadata and controls
42 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.gmail.orfejka;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
/*
* Создайте консольный «текстовый редактор» с возможностью сохранения
* набранного текста в файл.
*/
public static void main(String[] args) {
notepad();
}
static void notepad() {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the file name:");
String fileName = sc.nextLine();
File file = new File(fileName + ".txt");
StringBuffer sb = new StringBuffer();
System.out.println("Type the text . To to quit and save written text type the word \"exit\"");
String s = sc.nextLine();
while (!(s.equals("exit"))) {
sb.append(s);
s = sc.nextLine();
sb.append(System.lineSeparator());
}
try (PrintWriter pw = new PrintWriter(file)) {
pw.println(sb.toString());
} catch (IOException e) {
System.out.println(e);
}
}
}