Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Java Module 13

Files, I/O and NIO.2 interview questions

Interview questions on files, I/O and NIO.2 from Java: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

4 questions: 1 warm-up and 3 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    Why does line.split(",") fail on real CSV files, and what may a quoted field contain under RFC 4180?

    Answered in the lesson CSV, properties and structured text

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    A nightly job imports CSV statements from three banks. Some records come out with shifted columns, and one night 4,000 transactions were missing although the file was complete. How do you find the causes, and how do you make the import robust?

    What it tests
    How quoted commas, line breaks inside quotes, byte order marks and unclosed quotes break CSV readers, and an import that reports bad records with positions instead of shifting or losing data.
    First step
    Treat the two symptoms as two bugs. Count the fields of every record with a real CSV parser: records with more fields than the header were split at commas inside quotes, such as Indian-grouped amounts. Then compare the bank's transaction ids with the stored ones to find where the missing run starts.
    Follow-ups

    From the lesson CSV, properties and structured text

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Fresher to mid

    A Java service loads Hindi labels with Properties.load(new FileInputStream(file)). The file looks right in the editor, but the screen shows text like नम. Explain the cause, and fix it so that it cannot come back.

    What it tests
    How load(InputStream) decodes bytes as ISO 8859-1, why UTF-8 text turns into this pattern, and the choice between a UTF-8 Reader, escapes and a ResourceBundle.
    First step
    The file is fine; the way it is read is wrong. load(InputStream) is specified to decode every byte as one ISO 8859-1 character, and each Devanagari character is three bytes in UTF-8, so it becomes three Latin-1 characters, which is exactly the ठpattern on the screen.
    Follow-ups

    From the lesson CSV, properties and structured text

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    Your team adds a "Download as CSV" button for transaction reports that users open in spreadsheets, and a nightly CSV feed for a partner's system. Do you write the CSV code yourself or use a library? Defend the choice and say what each file must handle.

    What it tests
    Weighing hand-written code against a library, RFC 4180 quoting, formula injection in spreadsheet exports, encodings and line endings, and the difference between files for people and files for programs.
    First step
    Separate the two files by their reader: a program reads the feed, people read the download in a spreadsheet. List what each needs, quoting for both, a formula guard only for the download, streaming for large reports, then decide which option covers that list with the fewest risks.
    Follow-ups

    From the lesson CSV, properties and structured text

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Java interview questions · The Java track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.