Advertisement
Guest User

Java example

a guest
Jul 24th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 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.replace("    ",";").split(";");
  18.                 Float[] floats = new Float[values.length];
  19.                 for (int i = 0; i < values.length; i++) {
  20.                     floats[i] = Float.parseFloat(values[i].replace(",", "."));
  21.                 }
  22.                 data.add(Arrays.asList(floats));
  23.             }
  24.         } catch (IOException e) {
  25.             e.printStackTrace();
  26.         }
  27.  
  28.  
  29.         // wyświetlenie danych
  30.         for (var line : data) {
  31.             for (var value : line) {
  32.                 System.out.print(value + " ; ");
  33.             }
  34.             System.out.println("");
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement