title: Java: Keeping leading zeros while reading and formatting a text file
body: <p>I am having trouble figuring out how to read in a file, line by line, and then format it. The big issue is that I have a text file with a "number" assigned to a "person". The first number is "001". When I try to read it, it only saves as "1". It does the same thing with all leading zeros in my numbers. "002" becomes "2", "030" becomes "30", and so on. Each number has three digits and I want to keep it that way.</p>
  
  <p>Here is the bit of code where I read from the file:</p>
  
  <pre><code>do {
      next = Breader.readLine();
      sNumber = Integer.parseInt(next);
      nameArray.add(sNumber);
      sName = Breader.readLine();
      nameArray.add(sName);
      end = Breader.ready();
  } while(end);
  </code></pre>
  
  <p>It must be something in the <code>Integer.parseInt();</code> function.</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  import java.util.ArrayList;
  
  public class FinalProgram {
      public static void main(String[] args)  IOException {
          nameReader();
      }
  
      private static void nameReader() throws IOException {
          String nameFile = " ";
          String next = " ";
          int sNumber = 0;
          String sName = " ";
          Scanner input = new Scanner(System.in);
          ArrayList nameArray = new ArrayList();
  
          try {
              System.out.print("Enter the Name file(c:filename.txt): ");
              nameFile = input.nextLine();
          } catch(IllegalArgumentException e) {
              System.out.printf("Invalid input. Please enter"
                      + " filename in the form of "
                      + "c:filename.txt\n", e.getMessage());
          }
  
          //Instantiate FileReader and BufferedReader
          FileReader freader = new FileReader(nameFile);
          BufferedReader Breader = new BufferedReader(freader);
          boolean end = Breader.ready();
  
          do {
              next = Breader.readLine();
              sNumber = Integer.parseInt(next);
              nameArray.add(sNumber);
              sName = Breader.readLine();
              nameArray.add(sName);
              end = Breader.ready();
          } while(end);
  
          System.out.print(nameArray);
      }
  }
  </code></pre>