Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2020
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.stream.Collectors;
  6.  
  7. public class JavaClassOne {
  8.  
  9.     public static void main(String[] args) throws IOException {
  10.  
  11.         String currentDir = new File(".").getCanonicalPath();
  12.         List<List<Float>> data = new ArrayList<>();
  13.  
  14.         // wczytanie danych
  15.         try (BufferedReader br = new BufferedReader(new FileReader(currentDir + "/src/moj_plik_tekstowy.txt"))) {
  16.             String line;
  17.             while ((line = br.readLine()) != null) {
  18.                 String[] values = line.split(" ");
  19.                 Float[] floats = new Float[values.length];
  20.                 for (int i = 0; i < values.length; i++) {
  21.                     floats[i] = Float.parseFloat(values[i].replace(",", "."));
  22.                 }
  23.                 data.add(Arrays.asList(floats));
  24.             }
  25.         } catch (IOException e) {
  26.             e.printStackTrace();
  27.         }
  28.  
  29.  
  30.         // wyświetlenie danych
  31.         for (var line : data) {
  32.             for (var value : line) {
  33.                 System.out.print(value + " ; ");
  34.             }
  35.             System.out.println("");
  36.         }
  37.  
  38.         System.out.println("-------------------------------------");
  39.  
  40.         String path = currentDir +  "/src/moj_plik_tekstowy.txt";
  41.         BufferedReader br = new BufferedReader(new FileReader(path));
  42.  
  43.         List<String[]> data2 = br.lines()
  44.                 .map(s -> s.split(" "))
  45.                 .collect(Collectors.toList());
  46.  
  47.         for (var line : data2) {
  48.             for (var value : line) {
  49.                 System.out.print(value + " ; ");
  50.             }
  51.             System.out.println("");
  52.         }
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement