Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ćw6;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.util.HashSet;
- import java.util.LinkedList;
- import java.util.Scanner;
- import java.util.Set;
- public class File
- {
- static Set<String> SetNames = new HashSet<String>();
- static Set<String> SetSurnames = new HashSet<String>();
- static LinkedList<String> ListNames = new LinkedList<String>();
- static LinkedList<String> ListSurnames = new LinkedList<String>();
- public static void record() throws IOException
- {
- Scanner scanner = new Scanner(System.in);
- PrintStream namesWriter = new PrintStream(new FileOutputStream("Names.txt", true));
- PrintStream surnamesWriter = new PrintStream(new FileOutputStream("Surnames.txt", true));
- System.out.println("Podawaj imiona i nazwiska. Wyraz \"stop\" kończy wpisywanie\n");
- System.out.print("Podaj imię: ");
- String name = scanner.nextLine();
- System.out.print("Podaj nazwisko: ");
- String surname = scanner.nextLine();
- while (((name.equalsIgnoreCase("stop")) || (surname.equalsIgnoreCase("stop"))) == false)
- {
- namesWriter.println(name);
- surnamesWriter.println(surname);
- System.out.print("Podaj imię: ");
- name = scanner.nextLine();
- System.out.print("Podaj nazwisko: ");
- surname = scanner.nextLine();
- }
- System.out.println("\nWpisywanie zakończone!");
- namesWriter.close();
- surnamesWriter.close();
- scanner.close();
- }
- public static LinkedList<String> readingNames() throws FileNotFoundException, IOException
- {
- try
- {
- FileReader readNames = new FileReader("Names.txt");
- BufferedReader bufferedReaderNames = new BufferedReader(readNames);
- String line = bufferedReaderNames.readLine();
- while (line != null)
- {
- SetNames.add(line);
- line = bufferedReaderNames.readLine();
- }
- ListNames.addAll(SetNames);
- bufferedReaderNames.close();
- readNames.close();
- } catch (FileNotFoundException e)
- {
- System.err.println("Nie można odnalezć pliku o nazwie \"Names.txt\"");
- } catch (IOException e)
- {
- System.err.println("Nieznany błąd wejścia typu Input-Output");
- }
- return ListNames;
- }
- public static LinkedList<String> readingSurnames() throws FileNotFoundException, IOException
- {
- try
- {
- FileReader readSurnames = new FileReader("Surnames.txt");
- BufferedReader bufferedReadSurnames = new BufferedReader(readSurnames);
- String line = bufferedReadSurnames.readLine();
- while (line != null)
- {
- SetSurnames.add(line);
- line = bufferedReadSurnames.readLine();
- }
- ListSurnames.addAll(SetSurnames);
- bufferedReadSurnames.close();
- readSurnames.close();
- } catch (FileNotFoundException e)
- {
- System.err.println("Nie można znalezć pliku o nazwie \"Surnames.txt\"");
- } catch (IOException e)
- {
- System.err.println("Nieznany błąd wejścia typu Input-Output");
- }
- return ListSurnames;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement