Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package java18;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.nio.charset.Charset;
- import java.nio.file.Files;
- import java.nio.file.NoSuchFileException;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- public class ReaderFile {
- private static StringBuilder sb;
- static {
- sb = new StringBuilder();
- }
- public static void main(String[] args) {
- read(Paths.get("file.in"));
- }
- public final static void read(Path path) {
- try (BufferedReader rd = Files.newBufferedReader(path, Charset.forName("UTF-8"))) {
- while (sb.append(rd.readLine()).append(System.getProperty("line.separator")) != null
- && rd.ready())
- ;
- } catch (NoSuchFileException e) {
- System.err.println(String.format("File not exists: %s", e.getMessage()));
- } catch (IOException e) {
- System.err.println(e);
- } finally {
- System.out.println(sb);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement