Advertisement
Guest User

Untitled

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