Search This Blog

Java FileInputStream: Seek to offset using file channel

File f = File.createTempFile("aaa", null);

byte[] out = new byte[]{0, 1, 2};

FileOutputStream o = new FileOutputStream(f);
o.write(out);
o.close();

FileInputStream i = new FileInputStream(f);
i.getChannel().position(1);
assert i.read() == out[1];
i.close();
f.delete();

No comments:

Post a Comment