Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java read lines from file

        Scanner sc = null;
        try {
            File file = new File("myfile.txt"); // java.io.File
            sc = new Scanner(file);     // java.util.Scanner
            String line;
            while (sc.hasNextLine()) {
              line = sc.nextLine();
              // process the line
            }
          }
          catch(FileNotFoundException e)
          {
              e.printStackTrace();
          }
          finally {
            if (sc != null) sc.close();
          }
Comment

java read a line of input

// Java program to demonstrate working of Scanner in Java
import java.util.Scanner;
 
class GetInputFromUser {
    public static void main(String args[])
    {
        // Using Scanner for Getting Input from User
        Scanner in = new Scanner(System.in);
 
        String s = in.nextLine();
        System.out.println("You entered string " + s);
 
        int a = in.nextInt();
        System.out.println("You entered integer " + a);
 
        float b = in.nextFloat();
        System.out.println("You entered float " + b);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java method reference 
Java :: java inheritance 
Java :: java random double between 0 and 1 
Java :: crear objetos automaticamente java 
Java :: BufferredReader Class 
Java :: gat environment variables java 
Java :: how to add a list in a list java 
Java :: hide steam games from friends 
Java :: define an array of size n in java 
Java :: if driver.find_element_by_xpath selnium java is displayed 
Java :: error: package android.support.v7.app does not exist 
Java :: java decompiler 
Java :: regex pattern for bank cards validation 
Java :: read stream java 
Java :: How to efficiently reverse a singly linked list, in Java? 
Java :: java random number generator in range 
Java :: how to subtract localdatetime in java 
Java :: how to add spaces before string in java 
Java :: what is a do while loop in java 
Java :: how to put string in char array in java tutorialspoint 
Java :: swing getsource 
Java :: enum values to string array 
Java :: convert arraylist to array int 
Java :: sound file java 
Java :: java get class name of object 
Java :: java structure example 
Java :: online java code fixer 
Java :: arraylist vs vector in java 
Java :: set text in edittext android 
Java :: java loops 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =