title: How to use Java I/O to read file lines in a loop?
body: <p>I am trying to write DenverSortedCities and I did print exist file and but I need to write a loop to continue reading while there is more information in the file.</p>
  
  <p>As the loop cycle through all cities in the file, it will keep track of the <strong>largest city</strong> and its <strong>population</strong>. This is my code:</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      File inFile = new File("DenverSortedCities.txt");
  
      if (inFile.exists()){
          Scanner input = new Scanner(inFile);
  
          while(input.hasNextLine()){
              String cityInfo = input.nextLine();
              String[] cityInfoArray = cityInfo.split("0,1");
  
              int populationValue = Integer.parseInt(cityInfo);
          }
          System.out.println(input.nextLine());
  
          input.close();
      } else {
          System.out.println(inFile.getName() + " does not exist.");
          System.exit(1);
  
      }
  }
  </code></pre>