Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Talar;
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException{
- File plik = new File("C:\\Users\\TalarPC\\IdeaProjects\\Powturka\\baza.txt");
- Scanner in = new Scanner(plik);
- String linia;
- String [] pos;
- String [] imiona = new String[liczLinijki()];
- int i = 0;
- while(true){
- try{
- linia = in.nextLine();
- pos = linia.split("\\+");
- System.out.println(pos[0] + ", " + pos[1] + ", " + pos[2]);
- imiona[i] = pos[0];
- i++;
- }catch(NoSuchElementException e) { break; }
- }
- System.out.println("Tablica imion:");
- for(int j = 0; j < imiona.length; j++){
- System.out.println("Imie: " +imiona[j]);
- }
- }
- public static int liczLinijki() throws FileNotFoundException{
- File plik = new File("C:\\Users\\TalarPC\\IdeaProjects\\Powturka\\baza.txt");
- Scanner in = new Scanner(plik);
- String linia;
- int result = 0;
- while(true){
- try{
- linia = in.nextLine();
- result++;
- }catch(NoSuchElementException e) { break; }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement