Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileWriter;
  5. import java.util.*;
  6.  
  7.  
  8. public class s17014_p03 {
  9.  
  10. public static void main(String[] args) throws FileNotFoundException {
  11.  
  12. // odczyt danych z plikow do listy
  13.  
  14. ArrayList<Osoba> listaOsob = new ArrayList<>();
  15. File file = new File("dane01.txt");
  16. try {
  17. Scanner input = new Scanner(file);
  18. while (input.hasNext()) {
  19. String num = input.nextLine();
  20. System.out.println(num);
  21. listaOsob.add(new Osoba(num));
  22. }
  23. }
  24.  
  25. catch (FileNotFoundException e) {
  26. System.err.format("File Does Not Exist\n");
  27. }
  28.  
  29.  
  30. File file1 = new File("dane02.txt");
  31. try {
  32. Scanner input = new Scanner(file1);
  33. while (input.hasNext()) {
  34. String num = input.nextLine();
  35. System.out.println(num);
  36. listaOsob.add(new Osoba(num));
  37. }
  38. }
  39.  
  40. catch (FileNotFoundException e) {
  41. System.err.format("File Does Not Exist\n");
  42. }
  43.  
  44. // zapisywanie do pliku
  45.  
  46. try{
  47. FileWriter fw=new FileWriter("sortEska.txt");
  48. fw.write("Test");
  49. fw.close();
  50. }catch(Exception e){System.out.println(e);}
  51. System.out.println("Success...");
  52.  
  53. try{
  54. FileWriter fw=new FileWriter("sortName.txt");
  55. fw.write("Test");
  56. fw.close();
  57. }catch(Exception e){System.out.println(e);}
  58. System.out.println("Success...");
  59. }
  60.  
  61.  
  62. }
  63.  
  64.  
  65.  
  66. class Osoba {
  67.  
  68. private String imie;
  69. private String nazwisko;
  70. private int rokUrodzenia;
  71.  
  72. public Osoba(String input) {
  73.  
  74. String[] splitString = input.split(" ");
  75. this.imie = splitString[1];
  76. this.nazwisko = splitString[2];
  77. this.rokUrodzenia = Integer.parseInt(splitString[3]);
  78. }
  79. }
  80.  
  81.  
  82. //class Student extends Osoba{
  83. //
  84. // private String numerIndexu;
  85. //
  86. // super();
  87. //
  88. // public Student(String input){
  89. //
  90. // String[] splitString = input.split(" ");
  91. // this.numerIndexu = splitString[0];
  92. //
  93. // }
  94. //
  95. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement