Advertisement
janevim

CteniZeSouboru.java

Mar 7th, 2023
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class CteniZeSouboru {
  9.     private final static String ODDELOVAC = ";";
  10.     private final static String SOUBOR = "Soubor.txt";
  11.     private List<Deskovky> listGamesek = new ArrayList<>();
  12.  
  13.     public void vypis(){
  14.         try {
  15.             Scanner scanner = new Scanner(new BufferedReader(new FileReader(SOUBOR)));
  16.             listGamesek.clear();
  17.             while (scanner.hasNextLine()){
  18.                 String radek = scanner.nextLine();
  19.                 String[] casti = radek.split(ODDELOVAC);
  20.                 String nazev = casti[0];
  21.                 int oblibenost = Integer.parseInt(casti[1]);
  22.                 boolean zakoupeno = Boolean.parseBoolean(casti[2]);
  23.                 Deskovky gamesky = new Deskovky(nazev, oblibenost,zakoupeno);
  24.                 listGamesek.add(gamesky);
  25.             }
  26.             scanner.close();
  27.         } catch (FileNotFoundException e) {
  28.             throw new RuntimeException(e);
  29.         }
  30.     }
  31.  
  32.     public List<Deskovky> getListGamesek() {
  33.         return listGamesek;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement