I want to read an entire file into a byte array without newline or carriage return. I get 13,10 also in the byte array. Is there a way to read the entire file without newline or carriage return. I have used the below code:
InputStream in = new FileInputStream(file);
numBytesRead=in.read(result, offset, noBytes);
Is there any other way?
As far as I know, you'll have to filter that yourself:
byte[] raw = Files.readAllBytes(file.toPath());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (byte b : raw)
if (b != 10 && b != 13)
baos.write(b);
byte[] result = baos.toByteArray();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.