我有15Mb數據庫文件,我想在我的應用程序中使用。 我將該文件存儲在資產文件夾中。 因爲15Mb的大文件我不能複製該文件到SD卡。 我試過所有的東西.. 使用輸入流讀取文件是否有任何限制。 我的代碼適用於最大1Mb大小的數據文件,但不支持大於3to4 Mb。 我使我的文件壓縮,然後存儲到資產文件夾。如何將資產文件夾中的15Mb文件複製到SD卡...?
Here`s我的代碼:
private Thread thread = new Thread()
{
@Override
public void run()
{
// Create a directory in the SDCard to store the files
File file = new File(ROOT_FOLDER);
if (!file.exists())
{
file.mkdirs();
}
else
{
file.delete();
}
try
{
// Open the ZipInputStream
ZipInputStream in = new ZipInputStream(getAssets().open("lds_scriptures.zip"));
// Loop through all the files and folders
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();
//Toast.makeText(SdCardData.this, String.valueOf(size),2000).show();
Log.e("value",String.valueOf(size));
// Check if it is a folder
if (entry.isDirectory())
{
// Its a folder, create that folder
innerFile.mkdirs();
}
else
{
// Create a file output stream
FileOutputStream outputStream = new FileOutputStream(innerFileName);
final int BUFFER = 2048;
// Buffer the ouput to the file
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream,
BUFFER);
// Write the contents
int count = 0;
byte[] data = new byte[BUFFER];
while ((count = in.read(data, 0, BUFFER)) != -1)
{
bufferedOutputStream.write(data, 0, count);
}
// Flush and close the buffers
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
// sendMessage("DONE");
// Close the current entry
in.closeEntry();
}
in.close();
// sendMessage("-----------------------------------------------");
// sendMessage("Unzipping complete");
}
catch (IOException e)
{
sendMessage("Exception occured: " + e.getMessage());
e.printStackTrace();
}
}
};
private Handler handler = new Handler()
{
// @Override
public void handleMessage(Message msg)
{
// tv.append("\n" + msg.getData().getString("data"));
// super.handleMessage(msg);
}
};
private void sendMessage(String text)
{
Message message = new Message();
Bundle data = new Bundle();
data.putString("data", text);
message.setData(data);
handler.sendMessage(message);
}