Advertisement
Guest User

Untitled

a guest
May 28th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package java18;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.nio.charset.Charset;
  6. import java.nio.file.Files;
  7. import java.nio.file.NoSuchFileException;
  8. import java.nio.file.Path;
  9. import java.nio.file.Paths;
  10.  
  11. public class ReaderFile {
  12.  
  13. private static StringBuilder sb;
  14.  
  15. static {
  16. sb = new StringBuilder();
  17. }
  18.  
  19. public static void main(String[] args) {
  20. read(Paths.get("file.in"));
  21. }
  22.  
  23. public final static void read(Path path) {
  24. try (BufferedReader rd = Files.newBufferedReader(path, Charset.forName("UTF-8"))) {
  25.  
  26. while (sb.append(rd.readLine()).append(System.getProperty("line.separator")) != null
  27. && rd.ready())
  28. ;
  29.  
  30. } catch (NoSuchFileException e) {
  31. System.err.println(String.format("File not exists: %s", e.getMessage()));
  32. } catch (IOException e) {
  33. System.err.println(e);
  34. } finally {
  35. System.out.println(sb);
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement