I have 15 MB database files and I want to use them in my application. I saved this file in the resource folder. because of this large 15 MB file, I cannot copy this file to an SDCard. I tried everything. Is there a restriction on reading a file using the input stream. my code works well for data files up to 1 MB in size, but it does not support more than 3to4 MB. I make my zip file and then save it in the resources folder.
Here is my code:
private Thread thread = new Thread()
{
@Override
public void run()
{
File file = new File(ROOT_FOLDER);
if (!file.exists())
{
file.mkdirs();
}
else
{
file.delete();
}
try
{
ZipInputStream in = new ZipInputStream(getAssets().open("lds_scriptures.zip"));
for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in
.getNextEntry())
{
sendMessage("Extracting: " + entry.getName() + "...");
String innerFileName = ROOT_FOLDER + File.separator + entry.getName();
File innerFile = new File(innerFileName);
if (innerFile.exists())
{
innerFile.delete();
}
int size=in.available();
Log.e("value",String.valueOf(size));
if (entry.isDirectory())
{
innerFile.mkdirs();
}
else
{
FileOutputStream outputStream = new FileOutputStream(innerFileName);
final int BUFFER = 2048;
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream,
BUFFER);
int count = 0;
byte[] data = new byte[BUFFER];
while ((count = in.read(data, 0, BUFFER)) != -1)
{
bufferedOutputStream.write(data, 0, count);
}
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
in.closeEntry();
}
in.close();
}
catch (IOException e)
{
sendMessage("Exception occured: " + e.getMessage());
e.printStackTrace();
}
}
};
private Handler handler = new Handler()
{
public void handleMessage(Message msg)
{
}
};
private void sendMessage(String text)
{
Message message = new Message();
Bundle data = new Bundle();
data.putString("data", text);
message.setData(data);
handler.sendMessage(message);
}
source
share