Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java scan a file

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

public class ReadFile {

    public static void main(String[] args) {

        try {
            System.out.print("Enter the file name with extension : ");

            Scanner input = new Scanner(System.in);

            File file = new File(input.nextLine());

            input = new Scanner(file);


            while (input.hasNextLine()) {
                String line = input.nextLine();
                System.out.println(line);
            }
            input.close();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: android studio download 
Java :: each character in string java 
Java :: java.lang.string cannot be cast to java.lang.double react native 
Java :: immutable map java 
Java :: dequeue in java 
Java :: current time in long java 
Java :: java running sum of array 
Java :: android iinput edit text password icon change 
Java :: java string array to arraylist 
Java :: java loop using input user 
Java :: android studio change button color programmatically 
Java :: big java 2010 heaptree java program 
Java :: java final meaning 
Java :: java program for multiplication table 
Java :: raise error java 
Java :: java exception list 
Java :: java inheritance 
Java :: java indexof all occurrences 
Java :: add character to a string java 
Java :: for and while loops java 
Java :: java decompiler 
Java :: cors spring 
Java :: declare java class 
Java :: bytearrayoutputstream 
Java :: how to add spaces before string in java 
Java :: java variable declaration 
Java :: comment générer un nombre aléatoire en java 
Java :: not equal java 
Java :: how to change the character of a string in java 
Java :: java newinstance alternative 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =