Streams
Byte Streams Example:
import java.io.*; public class ByteStreamExample { public static void main(String[] args) { try { FileInputStream inputStream = new FileInputStream("input.txt"); int data; while ((data = inputStream.read()) != -1) { System.out.print((char) data); // Convert to char for text } inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }import java.io.*; public class ByteStreamExample { public static void main(String[] args) { try { FileOutputStream outputStream = new FileOutputStream("output.txt"); String text = "Hello, Byte Streams!"; byte[] bytes = text.getBytes(); outputStream.write(bytes); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }
Character Streams Example:
Last updated