Задача: "The Java Programming Language" Ken Arnold, James Gosling, David Holmes листинги, код, примеры из книги, исходники
Исходник: Глава 15, Ввод-Вывод (Chapter 15. Input-Output), FindChar class, язык: java [code #179, hits: 6012]
автор: - [добавлен: 15.09.2006]
  1. import java.io.FileReader;
  2. import java.io.IOException;
  3. import java.io.LineNumberReader;
  4.  
  5. /**
  6. * Created by IntelliJ IDEA.
  7. * User: me
  8. * Date: 13.09.2006
  9. * Time: 19:10:04
  10. * To change this template use File | Settings | File Templates.
  11. */
  12. public class FindChar {
  13. public static void main(String[] args) throws IOException {
  14. if (args.length != 2)
  15. throw new IllegalArgumentException("" +
  16. "It's needed: <symbol> and <file name>");
  17.  
  18. int match = args[0].charAt(0);
  19. FileReader fileIn = new FileReader(args[1]);
  20. int ch;
  21. while((ch = in.read()) != -1) {
  22. if (ch == match) {
  23. System.out.println("'" + (char)ch +
  24. "' at " + in.getLineNumber() + " string");
  25. return;
  26. }
  27. }
  28. System.out.println((char)ch + " not found");
  29. fileIn.close();
  30. }
  31. }
  32.  
Тестировалось на: java 1.5.0_04

+добавить реализацию