Here you can find the source of load(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] load(File file) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2012 by Min Cai (min.cai.china@gmail.com). * * This file is part of the PickaPack library. * * PickaPack 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 3 of the License, or * (at your option) any later version./*from w w w .j a v a 2 s . c o m*/ * * PickaPack 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 PickaPack. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ import java.io.*; public class Main { /** * * @param file * @return * @throws IOException */ public static byte[] load(File file) throws IOException { InputStream in = new FileInputStream(file); byte[] content = load(in, (int) file.length()); in.close(); return content; } /** * * @param in * @param length * @return * @throws IOException */ public static byte[] load(InputStream in, int length) throws IOException { byte[] buffer = new byte[length]; int offset = 0; for (;;) { int remain = length - offset; if (remain <= 0) { break; } int numRead = in.read(buffer, offset, remain); if (numRead == -1) { throw new IOException("Reached EOF, read " + offset + " expecting " + length); } offset += numRead; } return buffer; } }