Guys i have a file which has only one line. The file has no encoding it is a simple text file with single line.
For every 2048 byte i开发者_C百科n a line
, there is new record of 151 byte (totally 13*151 byte = 1945 records + 85 byte empty space)
. similarly for the next 2048 bytes.
What is the best file i/o to use? i am thinking of reading 2048 bytes from file and storing it in an array .
while (offset < fileLength &&(numRead=in.read(recordChunks, offset,alength)) >= 0)
{
}
how can i get from the read statement only 2048 bytes at a time . i am getting IndexOutofBoundException.
Just use a FileInputStream, the various read
methods will allow you to do what you need.
How about:
byte byte1 = dataArray[0];
byte byte2 = dataArray[1];
In my opinion, the easiest way to read data from a file is to use a BufferedReader :
try
{
BufferedReader br = new BufferedReader(new FileReader("your_file"));
//Read the first line
String s = br.readLine();
}
catch(Exception e)
{
e.printStackTrace();
}
Then just do what you want with the String you get !
Hope this helps.
精彩评论