Here you can find the source of openOutputStream(File file)
public static FileOutputStream openOutputStream(File file) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static FileOutputStream openOutputStream(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { throw new IOException("File '" + file + "' exists but is a directory"); }// w w w . ja v a 2 s . com if (!file.canWrite()) { throw new IOException("File '" + file + "' can not be written to"); } } else { File parent = file.getParentFile(); if (parent != null) { if (!parent.mkdirs() && !parent.isDirectory()) { throw new IOException("Directory '" + parent + "' can not be created"); } } } return new FileOutputStream(file); } }