CodeGym
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Reading text files: line by line and all at once

    JAVA 25 SELF
    Level 36, Lesson 1
    This lecture covers line-by-line reading with BufferedReader and whole-file reading via Files.readAllLines/ Files.readString, choosing a buffer (for example, 8192 bytes), safe resource closing with try-with-resources, and working with charsets ( StandardCharsets.UTF_8). It includes practical examples (counting lines, searching logs, parsing configuration) and common pitfalls (for example, OutOfMemoryError when loading large files at once).
    Available
  • Reading and writing binary files: InputStream, OutputStream

    JAVA 25 SELF
    Level 36, Lesson 2
    We cover the difference between text and binary files, the basic byte streams InputStream/ OutputStream and their file implementations ( FileInputStream, FileOutputStream). We write buffered copy, discuss read speed one byte at a time vs in blocks, writing byte arrays via write(), try-with-resources nuances, choosing a buffer size of 4– 16 KB, safe use of readAllBytes(), and common pitfalls (for example, using FileReader/ FileWriter for binary data).
    Available
  • DataInputStream, DataOutputStream: working with primitives

    JAVA 25 SELF
    Level 36, Lesson 3
    In this lecture, we examine binary I/O in Java using DataInputStream and DataOutputStream: how to write and read primitives ( int, double, boolean) and strings ( String) with writeXXX/ readXXX methods, why order matters, how to store arrays, when it makes sense to add BufferedInputStream/ BufferedOutputStream, and which common mistakes lead to IOException or EOFException.
    Available
  • Using try-with-resources: automatic resource closing

    JAVA 25 SELF
    Level 36, Lesson 4
    We break down the modern way to handle resources safely in Java — try-with-resources: a comparison with the old try/ catch/ finally + close() pattern, type requirements (implementing AutoCloseable or Closeable), the try(...){...} syntax, close order, “suppressed” exceptions via getSuppressed(), examples with I/O streams and custom resources, as well as tips and common mistakes.
    Available
  • What character encoding is and why it matters

    JAVA 25 SELF
    Level 37, Lesson 0
    We explain what character encoding is and why, without it, computer text turns into “mojibake.” We compare popular sets: UTF-8, Windows-1251, ASCII, Unicode/ UTF-16. We discuss the internal representation of strings in the JVM ( String in Unicode) and proper input/output: explicitly specifying the encoding via InputStreamReader/ OutputStreamWriter and StandardCharsets.UTF_8. Finally — practical examples and common mistakes.
    Available
  • Core encodings: UTF-8, UTF-16, ISO-8859-1

    JAVA 25 SELF
    Level 37, Lesson 1
    We break down three basic encodings a Java developer encounters: what UTF-8 is (the standard for the web and most formats), how the internal string format in the JVM works — UTF-16 (with surrogate pairs and BOM), and why ISO-8859-1 still appears. We explain compatibility with ASCII, bytes per character, and demonstrate correct encoding handling in Java using StandardCharsets, Files.write, Files.readString, Paths.get. Finally, we cover typical pitfalls: incorrect read/write, the system “default” encoding, confusion between UTF-16/ UTF-8.
    Available
  • Setting the encoding when reading/writing files

    JAVA 25 SELF
    Level 37, Lesson 2
    How to avoid “mojibake” and make text look the same on all machines: examine the system encoding ( "file.encoding"), work with Charset and the constants in StandardCharsets, read/write via Files . newBufferedReader and Files . newBufferedWriter, use try-with-resources, check available encodings, and follow best practices (by default — "UTF-8"). Finally — common mistakes and how to avoid them.
    Available
  • Encoding mismatches and common errors

    JAVA 25 SELF
    Level 37, Lesson 3
    In this lecture we examine “mojibake”, character loss ( ?), exceptions like MalformedInputException, the causes (mismatch between Windows-1251/ UTF-8, the system default encoding, BOM), diagnostics ( file.encoding), and best practices: explicitly specifying a Charset, using Files/ BufferedReader with StandardCharsets, avoiding FileReader/ FileWriter, and nuances for XML/ JSON and BOM.
    Available
  • Re-encoding files: reading in one encoding, writing in another

    JAVA 25 SELF
    Level 37, Lesson 4
    How to correctly read text from a file in one encoding and write it in another using classes from java.nio.file and java.io: use Files.newBufferedReader/ Files.newBufferedWriter or InputStreamReader/ OutputStreamWriter, specify the required Charset, apply try-with-resources, and avoid pitfalls of the system default encoding. Step-by-step algorithm, Windows-1251 → UTF-8 example, nuances (BOM, large files, exceptions), and common mistakes.
    Available
  • IOException and FileNotFoundException: error handling

    JAVA 25 SELF
    Level 38, Lesson 0
    How the I/O exceptions hierarchy in Java is structured, the difference between IOException and its subclass FileNotFoundException, when they occur, and how to handle them correctly. We will cover the order of catch blocks, hands-on file reading/writing, logging tips, as well as a brief table of the most frequent errors. We will touch on checked exceptions, the keywords try, catch, finally, throws, and the try-with-resources construct.
    Available
  • Checking for the existence of files and directories

    JAVA 25 SELF
    Level 38, Lesson 1
    How to check in Java whether a file or folder exists: the File class with its methods exists(), isFile(), isDirectory(), and the modern NIO approach via Path and Files — Files.exists(), Files.isRegularFile(), Files.isDirectory(). We will discuss the TOCTOU problem and why a pre-check does not replace error handling: even after exists() you can still get FileNotFoundException or AccessDeniedException, so always use try blocks and, when possible, try-with-resources. Plus hands-on practice: reading a file if present, creating a directory with Files.createDirectory() and Files.createDirectories(), working with relative and absolute paths.
    Available
  • Handling Corrupted Files, Data Recovery

    JAVA 25 SELF
    Level 38, Lesson 2
    How to recognize “broken” files by exceptions ( EOFException, MalformedInputException, ZipException, StreamCorruptedException), what to do when the format does not match, and which recovery strategies to use: logging and notifying the user, partial reading up to the error, backups, checksums ( SHA-256). Practice reading until EOF, correct handling of encodings, and analysis of common mistakes (validation, try-with-resources, careful overwrite).
    Available
  • 1
  • ...
  • 16
  • 17
  • 18
  • 19
  • 20
  • ...
  • 30
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym