I tested it on some file and it works fine for me. I doesn't switch order or do anything weird with text. Meaby I don't uderstand the task?
package pl.codegym.task.task19.task1924;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/*
Zastępowanie liczb
*/
public class Solution {
public static Map<Integer, String> map = new HashMap<Integer, String>();
static {
map.put(0, "zero");
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
map.put(4, "four");
map.put(5, "five");
map.put(6, "six");
map.put(7, "seven");
map.put(8, "eight");
map.put(9, "nine");
map.put(10, "ten");
map.put(11, "eleven");
map.put(12, "twelve");
}
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
String filename = reader.readLine();
reader.close();
BufferedReader fileReader = new BufferedReader(new FileReader(filename));
while (fileReader.ready()){
String[] splited = fileReader.readLine().split(" ");
String gg = "";
for (int x = 0; x < splited.length; x++){
try {
int y = Integer.parseInt(splited[x]);
if (y >= 0 && y <= 12) {
splited[x] = map.get(y);
}
}catch (NumberFormatException e){}
gg += splited[x] + " ";
}
System.out.print(gg);
System.out.println();
}
fileReader.close();
}catch (FileNotFoundException e){}
catch (IOException e){}
}
}