I want to set file length to zero. i used following code
try
{
new RandomAccessFile(file,"rw").setLength(0);
}
catch (FileNotFoundException e1)
{
// TODO Auto-generated catch block
Log.i("Exception caught ==> ", e1.toString());
e1.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
Log.i("Exception caught ==> ", e.toString());
e.printStackTrace();
}
The problem, if again anything i write in the file means, it showing some speacial character in the file like AAAAAAAAAAAA and followed my content. Please give me some suggestion.
The issue may be in read buffer. if you have want to read a file which has 10 bytes data and you have created a byte[] of 15 then you wil get extra null there. better create a byte array of size same as file length. also after getting string you can trim() the data
I have tried with the following code but didnot get any issue.
Sample Code