これは奇妙です。今は正常に動作します。おそらく私は間違った方法でそれをテストしました。
ここに問題がある人のための作業コードがあります:
final String path=getFilesDir().getParent()+"/t.txt";
RandomAccessFile newSparseFile=null;
try
{
new File(path).delete();
newSparseFile=new RandomAccessFile(path,"rw");
// create a 1MB file:
newSparseFile.setLength(1024*1024);
}
catch(final Exception e)
{
Log.e("DEBUG","error while creating file:"+e);
}
finally
{
if(newSparseFile!=null)
try
{
newSparseFile.close();
Log.d("DEBUG","length:"+new File(path).length());
}
catch(final IOException e)
{
Log.e("DEBUG","error while closing file:"+e);
}
}