Last active
January 11, 2024 12:24
-
-
Save oofnivek/ad7c1c7b4fb7f3a4436f43f87a058a63 to your computer and use it in GitHub Desktop.
Read file line by line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import java.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class Main { | |
public static void main(String[] args) { | |
try { | |
BufferedReader reader = new BufferedReader(new FileReader("fruits.txt")); | |
String line = reader.readLine(); | |
while(line != null){ | |
System.out.println(line); | |
line = reader.readLine(); | |
} | |
reader.close(); | |
} catch (FileNotFoundException e) { | |
throw new RuntimeException(e); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment