开发者

How Save Data Persistent From PHP to Android [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

How i save data from PHP to android persistently?

开发者_如何学编程

example: i want all string in www.google.com saved in parameter textstring, and i use it..


Use HttpClient. Then, with your InputStream, check this link:

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

And write it to the file you want.

A quick and dirty example:

// This goes inside a try...
HttpClient htc = new DefaultHttpClient();
HttpGet get = new HttpGet("http://www.google.com");
HttpResponse htr = null;
htr = htc.execute(get);
InputStream is = htr.getEntity().getContent();
File saveFile = new File(getApplicationContext().getFilesDir().getPath() + File.separatorChar + "datos.txt");
FileOutputStream fos = new FileOutputStream(saveFile);
// Validate if exists and so on...
int c;
while ((c = is.read()) != -1) 
{
    fos.write(c);
}
// Catch, finally, close, etc...

You may also want to buffer your reading and writing code.

Another method would be using:

InputStream is = URL("http://www.google.com").getContent();

It's up to you. I like HttpClient 'cos you can handle more things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜