Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Objects;
- import java.util.Scanner;
- public class FileManager {
- private String fileName;
- public FileManager(String fileName) {
- this.fileName = fileName;
- }
- public ArrayList<Double> getDataSetOneDimension() {
- ArrayList<Double> out = new ArrayList<>();
- for (File file : Objects.requireNonNull(new File("C:\\Users\\Marian\\IdeaProjects\\AILab2\\src\\datas").listFiles())) {
- if (file.getName().equals(fileName)) {
- try {
- FileInputStream fis = new FileInputStream(file);
- Scanner scan = new Scanner(fis);
- int length = scan.nextInt();
- for (int i = 0; i < length; i++) {
- out.add(scan.nextDouble());
- }
- } catch (FileNotFoundException e) {
- System.out.println("File" + file + "not found!");
- }
- }
- }
- return out;
- }
- public ArrayList<Double> getDataSetTwoDimensions() {
- ArrayList<Double> out = new ArrayList<>();
- for (File file : Objects.requireNonNull(new File("C:\\Users\\Marian\\IdeaProjects\\AILab2\\src\\datas").listFiles())) {
- if (file.getName().equals(fileName)) {
- try {
- FileInputStream fis = new FileInputStream(file);
- Scanner scan = new Scanner(fis);
- int length1 = scan.nextInt();
- int length2 = scan.nextInt();
- for (int i = 0; i < length1; i++){
- for (int j = 0; j < length2; j++){
- out.add(scan.nextDouble());
- }
- }
- } catch (FileNotFoundException e) {
- System.out.println("File" + file + "not found!");
- }
- }
- }
- return out;
- }
- public ArrayList<Double> getDataSetThreeDimensions() {
- ArrayList<Double> out = new ArrayList<>();
- for (File file : Objects.requireNonNull(new File("C:\\Users\\Marian\\IdeaProjects\\AILab2\\src\\datas").listFiles())) {
- if (file.getName().equals(fileName)) {
- try {
- FileInputStream fis = new FileInputStream(file);
- Scanner scan = new Scanner(fis);
- int length1 = scan.nextInt();
- int length2 = scan.nextInt();
- int length3 = scan.nextInt();
- for (int i = 0; i < length1; i++){
- for (int j = 0; j < length2; j++){
- for (int x = 0; x < length3; x++){
- out.add(scan.nextDouble());
- }
- }
- }
- } catch (FileNotFoundException e) {
- System.out.println("File" + file + "not found!");
- }
- }
- }
- return out;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement