Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.nio.charset.StandardCharsets;
- import java.nio.file.Files;
- import java.util.*;
- public class Manager {
- public void convert() throws IOException {
- List<Object> list = getOneData();
- try (PrintWriter csvWriter = new PrintWriter(new FileWriter("chebyrashka"));){
- for(Object item : list){
- csvWriter.println(item);
- }
- } catch (IOException e) {
- //Handle exception
- e.printStackTrace();
- }
- }
- public List<Object> getOneData() throws IOException {
- Scanner sc = new Scanner(System.in);
- System.out.println("Введіть номер заняття");
- int i = sc.nextInt();
- File file = new File("SingleseminarData.csv");
- List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
- List<Object> array = new ArrayList<>(lines.size());
- try {
- boolean a = false;
- for (String line : lines) {
- array = Arrays.asList(line.split(",", -1));
- if (i < array.size()) {
- System.out.println(array.get(0) + " " + array.get(i));
- a = true;
- }
- }
- if (!a) System.out.println("Ви ввели невірний номер заняття, будь ласка повторіть спробу");
- } catch (InputMismatchException e){
- System.out.println("Упс, здається ви ввели літеру. Будь ласка повторіть спробу");
- }
- return array;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement