Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4.  
  5. public class FileTesterTry {
  6. public static void main(String[] args) {
  7. String fileName = "testFile.txt";
  8.  
  9. try (
  10. FileReader fileReader = new FileReader(fileName);
  11. BufferedReader reader = new BufferedReader(fileReader);
  12. ) {
  13. String nextLine = null;
  14. int lines = 0;
  15. while ((nextLine = reader.readLine()) != null) {
  16. System.out.println(nextLine);
  17. lines++;
  18. }
  19. System.out.println("Ilość wierszy w pliku: " + lines);
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement