Facebook
From Adrian Pietrzak, 1 Week ago, written in Java.
Embed
Download Paste or View Raw
Hits: 25
  1. package com.company;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Files;
  5. import java.nio.file.Paths;
  6. import java.util.stream.Stream;
  7.  
  8. public class loadDataFromText {
  9.  
  10.     public void loadDataFromTxt() {
  11.         String fileName = "/Users/username/Desktop/file.txt";
  12.  
  13.         try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
  14.  
  15.             stream.limit(10).forEach(System.out::println);
  16.  
  17.         } catch (IOException e) {
  18.             e.printStackTrace();
  19.         }
  20.     }
  21.  
  22. }
  23.