Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

reading in lines from a file java

private ArrayList<String> readFileLines(String filepath) throws FileNotFoundException, IOException{
  File fp = new File(filepath);
  FileReader fr = new FileReader(fp);
  BufferedReader br = new BufferedReader(fr);

  ArrayList<String> lines = new ArrayList<>();
  String line;
  while((line = br.readLine()) != null) { lines.add(line); }

  fr.close();
  return lines;
}
Comment

java read each lines in file

        BufferedReader br = null;
        try {
            File file = new File("myfile.txt"); // java.io.File
            FileReader fr = new FileReader(file); // java.io.FileReader
            br = new BufferedReader(fr); // java.io.BufferedReader
            String line;
            while ((line = br.readLine()) != null) {
              // process the line
            }
          }
          catch(IOException e) { e.printStackTrace();}
          finally
          {
              try { if (br != null) br.close(); }
              catch(IOException e) { e.printStackTrace(); }
          }
Comment

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 run system command 
Java :: Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: minecraft chunk size 
Java :: JAVA_HOME not found in your environment. 
Java :: get hashmap into array 
Java :: update query jpa 
Java :: display an image java 
Java :: scanner check if int 
Java :: get certain character from string java 
Java :: try catch java 
Java :: conditions in for loop java 
Java :: java obtain list string from list object 
Java :: java_home should point to a jdk not a jre 
Java :: how to create a circle in java 
Java :: object to string in java 
Java :: reading csv file in java 
Java :: java filenotfoundexception 
Java :: open gallery android 
Java :: java arraylist to string 
Java :: java arraylist to array 
Java :: java string to decimal 
Java :: counting nodes in binary search tree 
Java :: get request java 
Java :: java main method 
Java :: Exception in thread "main" java.util.zip.ZipException: error 
Java :: How to swap two values in Java using a supporting method? 
Java :: java get date in utc 
Java :: who created java 
Java :: overloading + operator in java 
Java :: set ImageView size programmatically android 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =