There is a utility for comparing the files "test.txt" and "test1.txt". The command line is working properly. To run, enter "java -cp. CompFiles test.txt test1.txt"
(text files are pre-placed in one directory and everything works ok)
But how to start the program from Eclipse, at the same time to immediately specify the file names? When replacing FileInputStream (args [0]) with FileInputStream ("test.txt"), it still does not see the file in the directory.
import java.io.*; public class CompFiles { public static void main(String[] args) { int i = 0, j = 0; if (args.length != 2) { //убедиться, что имена файлов передаются программе System.out.println("Использование: Compfiles файл1 файл2"); return; } // Сравнить файлы try ( FileInputStream f1 = new FileInputStream(args[0]); FileInputStream f2 = new FileInputStream(args[1])) { //проверка содержимого файлов do { i = f1.read(); j = f2.read(); if(i !=j)break; } while (i != -1 && j != -1); if (i !=j) System.out.println("Содержимое отличачется"); else System.out.println("Содержимое совпадает"); } catch (IOException exc) { System.out.println("Ошибка ввода-вывода " + exc); } } }