I am currently using this:Path path = Paths.get(c:\test\test.txt);byte[] all= Files.readAllBytes(path);The problem with this is that I have to load the entire file in memory. My requirement is to read the file byte by byte, but in a manner like first 4 bytes mean X, next 16 bytes mean Y and use next 48 bytes for Z, etc.Right now I am looping through all to do this.. My current code has a pointer which I am moving till all.length and using Arrays.copyOfRange to copy parts to other arrays for use. I am interested in knowing about BufferedReaders which reads a few bytes and then I can process them.
Reading a file byte by byte in Java
java;file
You can use a data input and use the readFully(byte[]...) method. A quick way would be something like:byte[] header = new byte[4];byte[] name = new byte[16];DataInput input = new DataInputStream(new FileInputStream(file));input.readFully(header);input.readFully(name);input.close();