קבצים עם NIO ו-JSONFiles with NIO & JSON
Path ו-Files, קריאה וכתיבה של טקסט, CSV, ושמירה וטעינה של JSON.
Path and Files, reading and writing text, CSV, and saving and loading JSON.
בסוף המפגש תדעוBy the end you will
- לעבוד עם Path ו-Files: לכתוב, לקרוא, להוסיף ולבדוק אם קובץ קייםWork with Path and Files: write, read, append and check whether a file exists
- לקרוא ולכתוב CSV ולהפוך שורות ל-recordsRead and write CSV and turn lines into records
- לכתוב JSON בעצמכם ולהבין מה ספרייה כמו Jackson עושה בשבילכםWrite JSON yourself and understand what a library like Jackson does for you
- לטפל בקובץ חסר (
NoSuchFileException) ולסגור זרמי קבצים עם try-with-resourcesHandle a missing file (NoSuchFileException) and close file streams with try-with-resources
לפני שמתחיליםBefore you start
זמן: Time: כ-3 שעות (כולל הפסקה)About 3 hours (with a break)
דרישות קודמות: Prerequisites: מפגשים 1–28Sessions 1–28
מה צריך: You need: מחשב עם JDK 21 ו-IntelliJ IDEA מותקנים (מפגש 1). אפשר גם רק דפדפן: כל הקוד מוצג עם הפלט האמיתי שלו, ורץ גם כאן כשהדפדפן מאפשר.A computer with JDK 21 and IntelliJ IDEA (session 1). A browser alone also works: every example shows its real output, and runs here when the browser allows it.
סדר המפגשSession plan
- 0:00פתיחה וחזרה קצרהOpening and quick review
- 0:10מונחיםTerms
- 0:27לכתוב ולקרוא קובץWriting and reading a file
- 0:44להוסיף לסוף, ולקרוא כזרםAppending, and reading as a stream
- 1:01JSON בידJSON by hand
- 1:18הפסקהBreak
- 1:28קובץ שלא קייםA file that doesn't exist
- 1:45טעויות נפוצותCommon mistakes
- 2:02פרויקט מדףShelf project
- 2:19תרגולPractice
- 2:50סיכום ושאלותWrap-up and questions
Path ו-Files, קריאה וכתיבה של טקסט, CSV, ושמירה וטעינה של JSON. בסוף המפגש מוסיפים צעד לפרויקט המלווה.
Path and Files, reading and writing text, CSV, and saving and loading JSON. At the end we add a step to the companion project.
הפרויקט המלווהThe companion project: מדף: ספרייה אישיתShelf: a personal library
פרויקט אחד שגדל איתכם לאורך כל הקורס: מתחיל כתוכנית של 10 שורות, הופך למחלקות, ל-interfaces ול-streams, מייבא ספרים במקביל עם Threads, ונגמר כ-REST API.
One project that grows with you through the whole course: it starts as a 10-line program, becomes classes, interfaces and streams, imports books in parallel with threads, and ends as a REST API.
השלב של היוםToday's step המדף נשמר לקובץ ונטען ממנוThe shelf saves to a file and loads from it. לתרגילGo to the exercise