Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.File;
- import java.io.IOException;
- import java.nio.charset.Charset;
- import java.nio.file.Files;
- import java.util.ArrayList;
- import java.util.List;
- public class FileWork {
- private static final String READ_MAKE = "gamintojai.txt";
- private static final String READ_MODEL = "modeliai.txt";
- private static final String WRITE_PATH = "rezultatai.txt";
- private List<String> getFileContent(String file) throws IOException {
- return Files.readAllLines(
- new File(file).toPath(),
- Charset.defaultCharset()
- );
- }
- public List<Automobilis> gatherCars() throws IOException {
- List<Automobilis> cars = new ArrayList<>();
- List<String> makes = getFileContent(READ_MAKE);
- List<String> models = getFileContent(READ_MODEL);
- List<String> allMakes =new ArrayList<>();
- int key = 0;
- for (String make : makes) {
- String[] splitCount = make.split(" ");
- int makeCount = Integer.parseInt(splitCount[1]);
- for (int i = 0; i < makeCount; i++) {
- allMakes.add(splitCount[0]);
- String crrMake = models.get(key);
- String[] splitedModel = crrMake.split("\\s+(?=\\d)");
- cars.add(
- new Automobilis(
- splitCount[0],
- splitedModel[0],
- Integer.parseInt(splitedModel[1]),
- Float.parseFloat(splitedModel[2])
- )
- );
- key++;
- }
- }
- return cars;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement