🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io
Lesson: Basic I/O (The Java™ Tutorials > Essential Java Classes)
The lesson also looks at serialization, which lets a program write whole objects out to streams and read them back again. Then the lesson looks at file I/O and file system operations, including random access files. Most of the classes covered in the I/O Streams section are in the java.io package.
🌐
W3Schools
w3schools.com › java › java_files.asp
Java Files
The File class from the java.io package, allows us to work with files.
Discussions

File I/o Java

The official Java documentation is pretty good.

More on reddit.com
🌐 r/learnprogramming
2
1
November 1, 2022
[Java] need help understanding File and Data Input/Output Stream classes
The official tutorial has a whole section on IO Streams. For specific things about the classes and their methods you can always check the API documentation for java.io. More on reddit.com
🌐 r/learnprogramming
5
2
February 26, 2014
Oracle Java Tutorial [Essential Classes > Basic I/O > File ...
I am reading Oracle's Java tutorials, specifically the Web page entitled File Operations which is part of the Basic I/O lesson in the Essential Classes trail. According to the section entitled Wha... More on stackoverflow.com
🌐 stackoverflow.com
Why you should not use java.io.File
Title is misleading, it is not about Java itself, only about rule specific to a framework More on reddit.com
🌐 r/programming
12
0
September 3, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-io-input-output-in-java-with-examples
Input/Output in Java with Examples - GeeksforGeeks
Example: Java Program illustrating the Byte Stream to copy contents of one file to another file. ... import java.io.*; public class Geeks { public static void main( String[] args) throws IOException { FileInputStream sourceStream = null; FileOutputStream targetStream = null; try { sourceStream = new FileInputStream("sourcefile.txt"); targetStream = new FileOutputStream("targetfile.txt"); // Reading source file and writing content to target file byte by byte int temp; while (( temp = sourceStream.read()) != -1) targetStream.write((byte)temp); } finally { if (sourceStream != null) sourceStream.close(); if (targetStream != null) targetStream.close(); } } }
Published   December 10, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-io-tutorial
Java IO Tutorial - GeeksforGeeks
September 24, 2025 - The java.io package provides all the classes required for input and output. It supports operations like file handling, console input/output and working with data streams.
🌐
CodeHS
codehs.com › tutorial › 13902
Tutorial: File I/O in Java | CodeHS
Java Tutorial · java · By David Burnham · High School · java · By Evelyn Hunter · High School · All Products · Coding LMS · Online IDE · CodeHS Pro · Computer Science Curriculum · Certifications · Professional Development · AI Creator · Typing · Cyber Range ·
🌐
Tutorialspoint
tutorialspoint.com › java › java_files_io.htm
Java - Files and I/O
Failure indicates that the path specified in the File object already exists, or that the directory cannot be created because the entire path does not exist yet. The mkdirs() method creates both a directory and all the parents of the directory.
🌐
Upenn
engineering.upenn.edu › ~cis1xx › resources › java › fileIO › introToFileIO.html
Intro to File I/O
This is to ensure that the code in the finally block gets executed, even if the code within the try block causes an exception to be thrown (e.g. if you try to open a file for which you don't have permission). Don't worry if you don't understand it completely; you can copy and paste our examples in to your programs. import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class IOTest { public static void copyCharacters() throws IOException { FileReader inputStream = null; FileWriter outputStream = null; try { inputStream = new FileReader("xanadu.txt"); outputStream = new FileWriter("xanadu_output.txt"); int c; while ((c = inputStream.read()) != -1) { outputStream.write(c); } } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } } }
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java io › the java file class
The Java File Class | Baeldung
February 8, 2025 - In this tutorial, we’ll give an overview of the File class, which is part of the java.io API.
🌐
Medium
medium.com › @pratik.941 › mastering-input-output-i-o-in-java-a-comprehensive-guide-with-examples-0c7dc34cc016
Mastering Input/Output (I/O) in Java: A Comprehensive Guide with Examples | by Pratik T | Medium
June 9, 2024 - Java provides advanced I/O classes for more sophisticated I/O operations, such as serialization and memory-mapped files. Serialization allows converting an object into a byte stream for storage or transmission. `ObjectOutputStream` and `ObjectInputStream` are used for this purpose. import java.io.*; class Person implements Serializable { private static final long serialVersionUID = 1L; String name; int age; Person(String name, int age) { this.name = name; this.age = age; } } public class SerializationExample { public static void main(String[] args) { Person person = new Person("John Doe", 30);
🌐
Clemson University
people.computing.clemson.edu › ~yfeaste › cpsc215 › cpsc2150F15 › cpsc215Fall215 › Notes › Tutorialspoint_webpages › 18java_files_io.pdf pdf
Java - Files and I/O
Java provides strong but flexible support for I/O related to Files and networks but this tutorial covers · very basic functionality related to streams and I/O. We would see most commonly used example one ... Java byte streams are used to perform input and output of 8-bit bytes.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io › file.html
Reading, Writing, and Creating Files (The Java™ Tutorials > Essential Java Classes > Basic I/O)
File I/O Methods Arranged from Less Complex to More Complex · On the far left of the diagram are the utility methods readAllBytes, readAllLines, and the write methods, designed for simple, common cases. To the right of those are the methods used to iterate over a stream or lines of text, such as newBufferedReader, newBufferedWriter, then newInputStream and newOutputStream. These methods are interoperable with the java.io ...
🌐
Jenkov
jenkov.com › tutorials › java-io › index.html
Java IO Tutorial
March 15, 2020 - The purpose of this tutorial is to try to give you an overview of how all these classes are grouped, and the purpose behind them, so you don't have to wonder whether you chose the right class, or whether a class already exists for your purpose.
🌐
JDoodle
jdoodle.com › tutorials › java-module › java-beginner › basic-file-input-output-in-java
Basic File I/O in Java
JDoodle is an Online Compiler, Editor, IDE for Java, C, C++, PHP, Perl, Python, Ruby and many more. You can run your programs on the fly online, and you can save and share them with others. Quick and Easy way to compile and run programs online.
🌐
Reddit
reddit.com › r/learnprogramming › file i/o java
r/learnprogramming on Reddit: File I/o Java
November 1, 2022 -

Has anyone got any good videos explaining file I/o (read/write) in Java. Had a lesson today but my normal lecturer is sick and the guy who covered did a damn good job at confusing everyone for 3 hours rather than help us.

🌐
Dev.java
dev.java › learn › java-io
The Java I/O API - Dev.java
Java I/O is a set of classes that ... network. This tutorial will guide you through the Java I/O API, presenting the basic notions you need to understand in order to start writing Java code that takes advantage of the API...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-io-tutorial
Java IO Tutorial | DigitalOcean
August 4, 2022 - This post is an index of all Java IO articles. How to Create New File in Java In this post, you will learn how to create a new file in java program and use of “file.separator” system property to make our program platform independent.
🌐
Reddit
reddit.com › r/learnprogramming › [java] need help understanding file and data input/output stream classes
r/learnprogramming on Reddit: [Java] need help understanding File and Data Input/Output Stream classes
February 26, 2014 -

Hi guys,

I'm currently in my second semester of programming in java. I am working on an assignment that requires me to choose a file using JFileChooser and once i get that file i need to do certain things with it, such as create a backup of it using the data IO classes.

I have read the javadoc on these classes, but i dont understand it. I am able to get the file to back up using this method i wrote based off what i saw in class. however, i dont actually understand the individual roles of the FileIOStream and DataIOStream classes.

I feel as if i'm half assing it by writing code that i dont actually know what it does. I'd like to understand the difference between the File and Data IOstreams and why one of each object must be created in order to carry out the task.

Thanks in advance to anyone who can explain it to me.

TLDR wrote this method to back up a file but don't actually understand the roles of File and Data IOStream

Top answer
1 of 3
2
The official tutorial has a whole section on IO Streams. For specific things about the classes and their methods you can always check the API documentation for java.io.
2 of 3
2
You should not really be using DataInputStream and DataOutputStream (See notes below). A simpler version of your code might look like: (Note: I didn't include any error handling, just to make it somewhat more readable.) // Create a FileInputStream to read bytes from the input file. FileInputStream fin = new FileInputStream(f1); // Create a FileOutputStream that will write bytes to the output file. FileOutputStream fout = new FileOutputStream(fBackup); int aByte; do { aByte = fin.read(); // Read the next byte from the input file // If we haven't reached the end of the input file if (aByte != -1) { fout.write(aByte); // Write that byte to the destination file } // Loop while we haven't reached the end of the input file } while (aByte != -1); // Close the input and output streams. fin.close(); fout.close(); I think the comments explain what it's doing pretty well, but basically the idea is: Attempt to read a byte from the input file. If we haven't reached the end of the input file, write that byte to the output/backup file. If we haven't reached the end of the input file, go to step 1. Note that it's usually faster to read/write many bytes at once, rather than doing it one byte at a time. So you would typically want to use the read() and write() methods that accept a byte array parameter. === The DataInputStream and DataOuputStream class should really only be used if you want to read/decode and write/encode the specific java data types (int, double, etc). For general purpose file reading and writing that you want to perform at the byte level (you don't care what each byte represents), you can just use the plain FileInputStream and FileOutputStream classes.
🌐
Compsci
compsci.ca › v3 › viewtopic.php
[Tutorial] File I/O
June 21, 2006 - Computer Science Canada is a community for programmers and students to come and share there knowledge various subjects. We also have many tutorials and tips covering numerous languages and areas of programming.
🌐
Stack Overflow
stackoverflow.com › questions › 60937790 › oracle-java-tutorial-essential-classes-basic-i-o-file-operations-and-java
Oracle Java Tutorial [Essential Classes > Basic I/O > File ...
I am reading Oracle's Java tutorials, specifically the Web page entitled File Operations which is part of the Basic I/O lesson in the Essential Classes trail. According to the section entitled Wha...
🌐
Baeldung
baeldung.com › home › java › java io › java io series
Java IO Series | Baeldung
November 29, 2023 - Compare the Content of Two Files in Java · . . . . . Java IO – Conversions Series · . . . . . Guide to Java OutputStream · Guide to BufferedReader · . . . . . Introduction to the Java NIO2 File API · Java IO vs NIO · Java NIO2 Path API · A Guide to WatchService in Java NIO2 ·