can anyone helpe me solve this. I don't know how I can read an n byte field name, where n bytes come from s1 length of field name .

I am getting weird character output.

Welcome to the forum. I bet the bartender is going to ask you to change your name according to their naming policy. As to your question, I use a RandomAccessFile to read from an nth element. It also lets you specify the number of bytes to read.

If you are getting a weird character output, this may be due to the incorrect translation of the bytes into the correct character set. Try to use the new String(byte[] chars, Stirng characterSet) constructor for the String object.