OO Programming with Java


Streams

  1. Files' content are accessed by the way of Streams that are divided into two categories: Input or Output streams.
File file = new File("/home/thiry/eclipse-workspace/Course/catalog.csv");
try {
  FileOutputStream fos = new FileOutputStream(file);
  byte[] data = {'a','b','c'}; // "abc".getBytes();
  fos.write(data);
  fos.close(); // IMPORTANT: to free the resource
} catch (FileNotFoundException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}

Notice the succession of catch.


7 - 12