How to READ FILES with Java in 8 minutes! π
#java #javatutorial #javacourse import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException;...

Bro Code
30.2K views β’ Dec 14, 2024

About this video
#java #javatutorial #javacourse
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) {
// How to read a file using Java (3 popular options)
// BufferedReader + FileReader: Best for reading text files line-by-line
// FileInputStream: Best for binary files (e.g., images, audio files)
// RandomAccessFile: Best for read/write specific portions of a large file
String filePath = "C:\\Users\\User\\Desktop\\test.txt";
try(BufferedReader reader = new BufferedReader(new FileReader(filePath))){
String line;
while((line = reader.readLine()) != null){
System.out.println(line);
}
}
catch(FileNotFoundException e){
System.out.println("Could not locate file");
}
catch(IOException e){
System.out.println("Something went wrong");
}
}
}
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) {
// How to read a file using Java (3 popular options)
// BufferedReader + FileReader: Best for reading text files line-by-line
// FileInputStream: Best for binary files (e.g., images, audio files)
// RandomAccessFile: Best for read/write specific portions of a large file
String filePath = "C:\\Users\\User\\Desktop\\test.txt";
try(BufferedReader reader = new BufferedReader(new FileReader(filePath))){
String line;
while((line = reader.readLine()) != null){
System.out.println(line);
}
}
catch(FileNotFoundException e){
System.out.println("Could not locate file");
}
catch(IOException e){
System.out.println("Something went wrong");
}
}
}
Tags and Topics
Browse our collection to discover more content in these categories.
Video Information
Views
30.2K
Likes
638
Duration
6:54
Published
Dec 14, 2024
User Reviews
4.6
(6) Related Trending Topics
LIVE TRENDSRelated trending topics. Click any trend to explore more videos.
No specific trending topics match this video yet.
Explore All Trends