Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
How to WRITE FILES with Java in 8 minutes! ✍
Play lesson

Java tutorial for beginners ☕ - How to WRITE 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.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; public class Main { public static void main(String[] args) { // How to write a file using Java (4 popular options) // FileWriter = Good for small or medium-sized text files // BufferedWriter = Better performance for large amounts of text // PrintWriter = Best for structured data, like reports or logs // FileOutputStream = Best for binary files (e.g., images, audio files) String filePath = "test.txt"; String textContent = """ Roses are Red Violets are Blue BOOTY BOOTY BOOTY ROCKIN' EVERWHERE! """; try(FileWriter writer = new FileWriter(filePath)){ writer.write(textContent); System.out.println("File has been written"); } catch(FileNotFoundException e){ System.out.println("Could not locate file location"); } catch(IOException e){ System.out.println("Could not write file"); } } }

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