Все работает. Проверял и с отрицательными и с положительными.
package com.javarush.task.task18.task1820;
/*
Округление чисел
*/
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
BufferedReader reader = null;
BufferedInputStream stream = null;
BufferedOutputStream stream1 = null;
try {
reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
stream = new BufferedInputStream(new FileInputStream(file1));
stream1 = new BufferedOutputStream(new FileOutputStream(file2));
ArrayList<String > arrayList = new ArrayList<>();
String space = "";
while (stream.available() > 0){
int data = stream.read();
if (data == 32.0){
arrayList.add(space);
space = "";
}else {
space = space + (char)data;
if (stream.available() == 0){
arrayList.add(space);
}
}
}
for (int i = 0; i <arrayList.size() ; i++) {
BigDecimal bigDecimal = new BigDecimal(arrayList.get(i));
if (Double.parseDouble(arrayList.get(i)) > 0){
bigDecimal = bigDecimal.setScale(0,RoundingMode.HALF_UP);
String bd = bigDecimal + "";
stream1.write(bd.getBytes());
if (i == arrayList.size()-1) break;
stream1.write(32);
}
else if (Double.parseDouble(arrayList.get(i)) < 0){
bigDecimal = bigDecimal.setScale(0,RoundingMode.HALF_DOWN);
String bd = bigDecimal + "";
stream1.write(bd.getBytes());
if (i == arrayList.size()-1) break;
stream1.write(32);
}
}
}catch (Exception e){
}finally {
try {
reader.close();
stream.close();
stream1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/*D:\Темиртасов\Программирование!!!!\source.txt
D:\Темиртасов\Программирование!!!!\result.txt*/