title: Scanning integer and string from file in Java
body: <p>I'm new to Java and I have to read from a file, and then convert what I have read into variables. My file consists of a fruit, then a price and it has a long list of this. The file looks like this:</p>
  
  <pre><code>Bananas,4
  Apples,5
  Strawberry,8
  ...
  Kiwi,3
  </code></pre>
  
  <p>So far I have created two variables(<code>double price</code> and <code>String name</code>), then set up a scanner that reads from the file. </p>
  
  <pre><code>public void read_file(){
      try{
          fruits = new Scanner(new File("fruits.txt"));
          print_file();
      }
      catch(Exception e){
          System.out.printf("Could not find file\n");
      }                
  }
  public void print_file(){
  
      while(fruits.hasNextLine()){
          String a = fruits.nextLine();
          System.out.printf("%s\n", a);
          return;
      }
  }
  </code></pre>
  
  <p>Currently I am only able to print out the entire line. But I was wondering how I could break this up to be able to store the lines into variables.</p>