How to read ints from text file in Java

1 Answer

0 votes
package javaapplication1;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class JavaApplication1 {
  
    public static void main(String[] args) {
        try
        {   
            Scanner s = new Scanner(new File("d:\\data.txt"));
        
	    while(s.hasNextInt())
	    	System.out.println(s.nextInt());
	}
	catch(IOException e)
	{	
            System.out.println(e);
	}
    }
}
    
/*
run:
   
12
34
873
3
1917

*/

 



answered Jun 30, 2017 by avibootz
edited Jun 30, 2017 by avibootz

Related questions

1 answer 246 views
1 answer 363 views
1 answer 261 views
1 answer 367 views
1 answer 270 views
270 views asked Mar 8, 2015 by avibootz
...