Answers for "reading lines of input java system in"

1

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();
          }
Posted by: Guest on March-12-2020
0

how to get string input line in java

class me{
    public static void main(String[] args) {
        name();
    }
    public static void name(){
        Scanner input = new Scanner(System.in);
        System.out.print("Enter your name :");
        String full_name = input.nextLine();
        System.out.println("hi "+ full_name+", Welcome back !");
    }
Posted by: Guest on February-05-2022

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language