Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public static int[] Soubor(String soubor) {
  2. //try catch na errory
  3. try {
  4. //udelam objekt file, coz je muj soubor z parametru
  5. File file = new File(soubor);
  6. //scanner pro soubor
  7. Scanner s = new Scanner(file);
  8. int x = 0;
  9. //pokud je na dalsi pozici cislo, zvetsi pocitalo velikosti rady
  10. while (s.hasNext()) {
  11. x++;
  12. s.nextInt();
  13.  
  14. }
  15. s.close();
  16. int[] rada = new int[x];
  17. Scanner r = new Scanner(file);
  18. for(int i = 0;i<rada.length;i++) {
  19. rada[i] = r.nextInt();
  20. }
  21. r.close();
  22. return rada;
  23.  
  24. } catch (FileNotFoundException e) {
  25. return null;
  26. // TODO Auto-generated catch block
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement