I run the program: java Main Tetst.txt The contents of the file is deleted.
import java.io.*; public class Main { public static void main(String args[]){ int i; char string []; FileInputStream fin; FileOutputStream fos; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; String name_file = args[0]; if (args.length!=1){ System.out.println(args[0]); return; } try{ fin = new FileInputStream(name_file); fos = new FileOutputStream(name_file); } catch (FileNotFoundException e){ System.out.println("Невозможно открыть файл"); return; } try{ do{ i = fin.read(); if(i!=-1)System.out.print((char) i); } while (i !=-1); } catch (IOException e){ System.out.println("Ошибка чтения из файла"); } try { do { str = br.readLine(); string = str.toCharArray(); if (!str.equalsIgnoreCase("Exit")) { for (int j = 0; j < str.length(); j++) { fos.write(string[j]); } } } while (!str.equalsIgnoreCase("Exit")); }catch (IOException e){ System.out.println("Ошибка чтения / записи"); } finally { try{ fin.close(); }catch (IOException e){ System.out.println("Ошибка закрытия файла"); } } } }