Here you can find the source of writeFile(final String filename, final byte[] data)
Parameter | Description |
---|---|
filename | The filename. Can be '-' for writing to stdout. |
data | The data to write. |
Parameter | Description |
---|---|
IOException | When write fails. |
public static void writeFile(final String filename, final byte[] data) throws IOException
//package com.java2s; /*// w w w.j a v a 2 s. c o m * Copyright (C) 2011 Klaus Reimer <k@ailis.de> * See LICENSE.md for licensing information. */ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { /** * Writes data to a file. * * @param filename * The filename. Can be '-' for writing to stdout. * @param data * The data to write. * @throws IOException * When write fails. */ public static void writeFile(final String filename, final byte[] data) throws IOException { if (filename.equals("-")) { System.out.write(data); return; } try (final OutputStream stream = new FileOutputStream(filename)) { stream.write(data); } } }