Example: A simple Java program to show the concept of Input/Output Stream.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
  public static void main(String[] args) {
    try {
      // Create a file input stream
      FileInputStream in = new FileInputStream(new File("input.txt"));
      
      // Create a file output stream
      FileOutputStream out = new FileOutputStream(new File("output.txt"));
      
      // Read data from input file and write it to output file
      int c;
      while ((c = in.read()) != -1) {
        out.write(c);
      }
      
      // Close streams
      in.close();
      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Loading

Categories: Java

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.