forked from levelp/java_01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
23 lines (20 loc) · 1005 Bytes
/
Copy pathMain.java
File metadata and controls
23 lines (20 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package java;
import javax.swing.*;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
System.out.println("Working Directory = " + System.getProperty("user.dir"));
try {
// Читаем текстовый файл
String text = new String(Files.readAllBytes(Paths.get("10_ReadTextDemo\\text.txt")), "UTF-8");
// Выводим его содержимое в консоль
System.out.println(text);
// Показываем содержимое файла пользователю в диалоговом окне
JOptionPane.showMessageDialog(null, text, "Текст", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
// Выводим диалог с его содержимым на экран
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}