Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
How to READ FILES with Java in 8 minutes! 📖
Play lesson

Java tutorial for beginners ☕ - How to READ FILES with Java in 8 minutes! 📖

5.0 (4)
40 learners

What you'll learn

This course includes

  • 12 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#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"); } } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere