Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

read file java line

package com.journaldev.readfileslinebyline;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadFileLineByLineUsingBufferedReader {

	public static void main(String[] args) {
		BufferedReader reader;
		try {
			reader = new BufferedReader(new FileReader(
					"/Users/pankaj/Downloads/myfile.txt"));
			String line = reader.readLine();
			while (line != null) {
				System.out.println(line);
				// read next line
				line = reader.readLine();
			}
			reader.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

PREVIOUS NEXT
Code Example
Java :: store files system in tree java 
Java :: open youtube by default in full screen pragmatically in android 
Java :: custom validator arrays 
Java :: efficient generic duplicate finding class java 
Java :: how to hide password in java code 
Java :: click selectable in androiod 
Java :: Java Documenting assumptions 
Java :: Java Public Access Modifier package one 
Java :: reference value in array list java syntax 
Java :: url encode not working spring boot oauth2 
Java :: java virtual override 
Java :: OkHttp3 Never Timeout on slow internet 
Java :: is java good then c++ is good 
Java :: @column spring boot jpa 
Java :: what is assignment in java with example 
Java :: set class return type by jenric in java 
Java :: how to get latest artifact from nexus and deployed in tomcat 
Java :: android java onUpgrade() 
Java :: You may test the newly compiled and packaged JAR in maven 
Java :: before first method in jdbc 
Java :: how does java knows where it has stored primitive data type 
Java :: jks not found when trying googlenethttptransport 
Java :: your application is missing a valid safety identifier 
Java :: java declare 2d array with values 
Java :: load local json 
Java :: Java Using range(e1, e2) Method 
Java :: ordenar numeros java 
Java :: okhttp Sending and Receiving Network Requests 3 21 
Java :: Java Copying Arrays Using Assignment Operator 
Java :: activity show 1 time in android studio java 2022 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =