Advertisement
cd62131

scan integer

Apr 24th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.47 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.   public static void main(String[] args) {
  8.     File f = new File("sample.txt");
  9.     Scanner in = null;
  10.     try {
  11.       in = new Scanner(f);
  12.     }
  13.     catch (Exception e) {
  14.     }
  15.     List<Integer> array = new ArrayList<Integer>();
  16.     while (in.hasNext()) {
  17.       array.add(new Integer(in.next()));
  18.     }
  19.     System.out.println(array);
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement