scofield
چهارشنبه 25 تیر 1393, 16:33 عصر
سلام یه سوال دارم ؟
من یه دیتابیس دارم که توی پوشه Assete قرار دادم و با این کد اونو به برنامه وصل کردم
اولا اینکه این روش درسته و سوال مهمترم اینه که چطوری میتونم اطلاعات این دیتابیس رو روی یک listview نمایش بدم
واقعا ممنون میشم اگه کمکم کنید خیلی وقتمو گرفت ولی نتونستم حل کنم مشکلمو
try { String destPath = "/data/data/" + getPackageName() +
"/assets";
File f = new File(destPath);
if (!f.exists()) {
f.mkdirs();
f.createNewFile();
//---copy the db from the assets folder into
// the databases folder---
CopyDB(getBaseContext().getAssets().open("MyDB"),
new FileOutputStream(destPath + "/MyDB"));
Log.i("ali", "ok!");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
public void CopyDB(InputStream inputStream, OutputStream outputStream) throws IOException {
//---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
من یه دیتابیس دارم که توی پوشه Assete قرار دادم و با این کد اونو به برنامه وصل کردم
اولا اینکه این روش درسته و سوال مهمترم اینه که چطوری میتونم اطلاعات این دیتابیس رو روی یک listview نمایش بدم
واقعا ممنون میشم اگه کمکم کنید خیلی وقتمو گرفت ولی نتونستم حل کنم مشکلمو
try { String destPath = "/data/data/" + getPackageName() +
"/assets";
File f = new File(destPath);
if (!f.exists()) {
f.mkdirs();
f.createNewFile();
//---copy the db from the assets folder into
// the databases folder---
CopyDB(getBaseContext().getAssets().open("MyDB"),
new FileOutputStream(destPath + "/MyDB"));
Log.i("ali", "ok!");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
public void CopyDB(InputStream inputStream, OutputStream outputStream) throws IOException {
//---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}