fork download
  1. import java.io.BufferedReader;
  2. import java.io.FileInputStream;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6. import java.io.IOException;
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. Scanner sc = new Scanner(System.in);
  11. String sEncode = "UTF-8";
  12. String sFInput = "input.txt";
  13. ArrayList<String> dalsData = new ArrayList<String>();
  14. String line;
  15. try ( // これはtry-with-resources文なので、
  16. // 自動クローズがサポートされるから、明示的なクローズは必要ない。
  17. BufferedReader reader = new BufferedReader(
  18. new InputStreamReader(
  19. new FileInputStream(sFInput), sEncode)); //
  20. ) {
  21. System.out.println("<File Input>");
  22. while (null != (line = reader.readLine())) {
  23. dalsData.add(line);
  24. System.out.println(line);
  25. }
  26. } catch (IOException ex) {
  27. ex.printStackTrace();
  28. }
  29. System.out.println();
  30. while (true) {
  31. System.out.println("<Input Keyword>");
  32. String sKeyword = sc.nextLine();
  33. if (sKeyword.equals("")) {
  34. break;
  35. }
  36. int ix = -1;
  37. for (int i = 0; i < dalsData.size(); i++) {
  38. if (dalsData.get(i).equals(sKeyword)) {
  39. ix = i;
  40. break;
  41. }
  42. }
  43. if (ix < 0) {
  44. System.out.println("<Not Existence>");
  45. } else {
  46. System.out.println("<Index>: " + ix);
  47. }
  48. System.out.println();
  49. }
  50. System.out.println("<End Of Program>");
  51. }
  52. }
  53.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty