Witam, mam taki problem, zeby zapisac plik jako tablice bajtow. Moj kod :

public class ReadFileByteArray{
// Returns the contents of the file in a byte array.
    public static byte[] bajty(File file) throws IOException {
        InputStream is = new FileInputStream(file);
        long length = file.length();
        byte[] bytes = new byte[(int)length];
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }
        if (offset < bytes.length) {
            throw new IOException("Nie mozna calkowicie odczytac pliku"+file.getName());
        }
        is.close();
        return bytes;
    }
}

dziala, ale tylko dla stosunkowo niewielkich plikow. Jesli dlugosc pliku jest wieksza od rozmiaru inta to metoda sie wywala.
Moze ktos pomoc jak sobie z tym poradzic?

Teraz widze, ze problem chyba nie jest w tym co mowilem....
Wyskakuje mi wyjatek OutOfMemoryError jak moge sobie z tym poradzic?

Juz sobie poradzilem, zwiekszenie stosu pomoglo.