Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Text files: write and read with Scanner · ⁨ไฟล์ข้อความ: เขียนและอ่านด้วย Scanner⁩

English

Reading and writing text files

  • A text file stores text that stays on disk after the program ends.
  • To read a file in Java we use a Scanner connected to a File.
  • To write a file we use a PrintWriter. In this lesson each program writes a file, then reads it back.
  • Bonus lesson: the AP CSA exam does not test file input/output. Learn this for real programs — you will not be examined on it.
ไทย

การอ่านและเขียนไฟล์ข้อความ

  • ไฟล์ข้อความ เก็บข้อความไว้บนดิสก์หลังจากโปรแกรมสิ้นสุดลง
  • เพื่อ อ่าน ไฟล์ใน Java เราใช้ Scanner ที่เชื่อมต่อกับ File
  • เพื่อ เขียน ไฟล์เราใช้ PrintWriter ในบทเรียนนี้แต่ละโปรแกรมจะ เขียน ไฟล์ แล้ว อ่าน กลับมา
  • บทเรียนเสริม: การสอบ AP CSA ไม่ ทดสอบ การอินพุต/เอาต์พุตไฟล์ เรียนรู้นี้สำหรับโปรแกรมจริง — คุณจะไม่ได้ถูกทดสอบเรื่องนี้

Handout · ⁨เอกสารประกอบการเรียน⁩

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP