У меня есть два файла, в первом записан один символ - "1", во втором - "2".
Вот код моей программы:
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName1 = reader.readLine();
String fileName2 = reader.readLine();
FileInputStream fileInputStream = new FileInputStream(fileName1);
byte[] one = new byte[fileInputStream.available()];
if (fileInputStream.available()>0) {
int count = fileInputStream.read(one);
}
FileOutputStream fileOutputStream = new FileOutputStream(fileName1);
FileInputStream fileInputStream2 = new FileInputStream(fileName2);
byte[] two = new byte[fileInputStream2.available()];
if (fileInputStream2.available()>0) {
int count = fileInputStream2.read(two);
}
fileOutputStream.write(two);
fileOutputStream.write(one);
fileInputStream.close();
fileInputStream2.close();
fileOutputStream.close();
}
}
Почему после ее выполнения у меня в первом фале хранится "21", а не "121"? В каком моменте из файла удаляется изначальная единица? Почему это происходит?
Заранее спасибо!