во второй файл записывается какая-то дичь... Дебаг показывает, что все числа отлично округляются.
шшшшшшшшшшшш
Что не так?
package com.javarush.task.task18.task1820;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Scanner;
/*
Округление чисел
*/
public class Solution {
public static void main(String[] args) throws IOException {
InputStreamReader inputStreamReader = new InputStreamReader(System.in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
// String fileNameInput = bufferedReader.readLine();
// BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
Scanner scanner1 = new Scanner(System.in);
String file = scanner1.nextLine();
Scanner scanner2 = new Scanner(new File(file));
String fileNameOutput = bufferedReader.readLine();
FileOutputStream fileOutputStream = new FileOutputStream(fileNameOutput);
String[] split;
int index = 0;
double temp;
int temp2 = 0;
while (scanner2.hasNextLine()) {
split = scanner2.nextLine().split(" ");
while (true) {
try {
temp = Double.parseDouble(split[index]);
} catch (ArrayIndexOutOfBoundsException e) {
break;
}
if (temp > 0) {
temp2 = (int) Math.round(temp);
} else if (temp < 0) {
temp2 = (int) Math.round(temp);
}
index++;
fileOutputStream.write((byte)temp2);
}
}
bufferedReader.close();
fileOutputStream.close();
// byte[] b = bufferedInputStream.readAllBytes();
// Byte[] bytes = new Byte[b.length];
// for (int i = 0; i < bytes.length; i++) {
// bytes[i] = b[i];
// }
// ArrayList<Byte> aByte = new ArrayList<>(Arrays.asList(bytes));
// System.out.println(aByte);
}
}
И для чего тебе столько сканеров?Этот сканер дает возможность вбить в консоль строку. А этот сканер считывает данные из файла.