Read data from a text file using Java

后端 未结 16 1540
挽巷
挽巷 2020-12-10 05:35

I need to read a text file line by line using Java. I use available() method of FileInputStream to check and loop over the file. But while reading,

16条回答
  •  伪装坚强ぢ
    2020-12-10 06:13

    //The way that I read integer numbers from a file is...
    
    import java.util.*;
    import java.io.*;
    
    public class Practice
    {
        public static void main(String [] args) throws IOException
        {
            Scanner input = new Scanner(new File("cards.txt"));
    
            int times = input.nextInt();
    
            for(int i = 0; i < times; i++)
            {
                int numbersFromFile = input.nextInt();
                System.out.println(numbersFromFile);
            }
    
    
    
    
        }
    }
    

提交回复
热议问题