Here you can find the source of writeFile(String path, byte[] data)
Parameter | Description |
---|---|
path | the path of a file. |
data | data to write. |
public static boolean writeFile(String path, byte[] data)
//package com.java2s; /************************************************************************************************* * Class of utility methods/* w w w . j a va 2 s. c o m*/ * Copyright (C) 2000-2006 Mikio Hirabayashi * This file is part of QDBM, Quick Database Manager. * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU * Lesser General Public License as published by the Free Software Foundation; either version * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * You should have received a copy of the GNU Lesser General Public License along with QDBM; if * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. *************************************************************************************************/ import java.io.IOException; import java.io.OutputStream; import java.io.FileOutputStream; public class Main { /** * Write whole data to a file. * @param path the path of a file. * @param data data to write. * @return true if success, false on failure. */ public static boolean writeFile(String path, byte[] data) { OutputStream os = null; try { os = new FileOutputStream(path); os.write(data); } catch (IOException e) { return false; } finally { try { if (os != null) os.close(); } catch (IOException e) { } } return true; } }