我要疯了!也许有人可以帮助我?!我在正在运行的服务器上有一个 sqlite 数据库,由于 php 脚本而收到该数据库。(为了清楚起见:我正在调用一个 php 脚本,它为我提供数据库作为响应)。有了响应,我现在尝试将其“解析”为常规的 *.db 文件,稍后我将其用于我的应用程序。
该应用程序运行良好,同时将 *.db 放入 assets 文件夹中。但是每次调用应用程序时我都需要获取更新的数据库。因此我需要以某种方式从服务器接收它。
只是为了通知:我不知道他们为什么为此使用 php 脚本,但它与应用程序的 iOS 版本完美配合。所以我 100% 确定脚本确实有效。
有任何提示或解决方案吗?谢谢!
编辑:这就是我想要做的。private void copyDatabase() { InputStream myInputDB = null; 输出流 myOutputDB = null; HttpResponse 响应 = null; // 刚刚创建的空数据库的路径 String dbFilePath = DB_PATH + KeyConstants.DB_NAME;
// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpPost httpPost = new HttpPost(
"http://USERNAME:PASSWORD@ADRESS/u/db.php");
try {
response = httpClient.execute(httpPost);
//Open your local db as the input stream
myInputDB = response.getEntity().getContent();
//Open the empty db as the output stream
myOutputDB = new FileOutputStream(dbFilePath);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInputDB.read(buffer)) > 0){
myOutputDB.write(buffer, 0, length);
}
//Close the streams
myOutputDB.flush();
myOutputDB.close();
myInputDB.close();
} catch (IOException ioEXC) {
throw new Error("Problem copying database from resource file.");
}