Here you can find the source of dumpFile(String filename)
Parameter | Description |
---|---|
filename | The name of the file to be dumped. |
public static byte[] dumpFile(String filename) throws IOException
//package com.java2s; /*//from ww w .ja va 2 s. c om This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Copyright (C) 2005 Marco Aurelio Graciotto Silva <magsilva@gmail.com> */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { /** * Dump a file content to an array of bytes. * * @param filename * The name of the file to be dumped. */ public static byte[] dumpFile(String filename) throws IOException { return dumpFile(new File(filename)); } /** * Dump a file content to an array of bytes. * * @param file * The file to be dumped. */ public static byte[] dumpFile(File file) throws IOException { FileInputStream stream = new FileInputStream(file); byte[] data = new byte[(int) file.length()]; stream.read(data, 0, (int) file.length()); stream.close(); return data; } }