1 import java.io.*; 2 3 public class TestFileStream { 4 public static void main(String[] args) throws IOException { 5 try ( 6 // Create an output stream to the file 7 FileOutputStream output = new FileOutputStream("temp.dat"); 8 ) { 9 // Output values to the file 10 for (int i = 1; i <= 10; i++) 11 output.write(i); 12 } 13 14 try ( 15 // Create an input stream for the file 16 FileInputStream input = new FileInputStream("temp.dat"); 17 ) { 18 // Read values from the file 19 int value; 20 while ((value = input.read()) != -1) 21 System.out.print(value + " "); 22 } 23 } 24 }