Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. /**
  8. * Created by Иван on 09.10.2017.
  9. */
  10. public class Reader {
  11. public static List<String> read(String fileName) throws FileNotFoundException {
  12. Scanner scanner = new Scanner(fileName);
  13. List<String> list = new ArrayList<>();
  14. while(scanner.hasNextLine()) {
  15. list.add(scanner.nextLine());
  16. }
  17. return list;
  18. }
  19.  
  20. public static String readAsString(String fileName) throws FileNotFoundException {
  21. Scanner scanner = new Scanner(new File(fileName));
  22. StringBuilder sb = new StringBuilder();
  23. while(scanner.hasNextLine()) {
  24. sb.append(scanner.nextLine());
  25. }
  26. return sb.toString();
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement