0
InputStream in = null;
try {
    in = urlConnection.getInputStream();
}
BufferedReader reader =new BufferedReader(new InputStreamReader(in));
Log.d("before endfdfdfdtering loop"," ");
StringBuilder str = new StringBuilder();
String line=null;

try {
    str.append(reader.readLine());
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

try {
    while((line=reader.readLine())!=null)
    {
        str.append(line);
    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

try {
    in.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

String result=str.toString();

result=result.replaceAll(" ","");
Log.d("before entering loop"," "+result);

boolean flag;
if(result.equals("1"))
    flag = true;
else
    flag = false;

Above written is the code i have for getting data from local host but i cannot understand the code , Can someone please explain it and also tell me what to write on server side ( PHP language) to send data on android emulator . I have posted data to server from android emulator but do not know how to get data from server to Emulator.

i would want to send 2 strings from server to android emulator

1 Answers1

0

I would start here:

http://developer.android.com/reference/java/lang/StringBuilder.html

and

http://developer.android.com/reference/java/io/BufferedReader.html

The classes for java ( and androids java ) are pretty well documented, i always start there when im not sure how something is working.

Also, it seems a bit strage they way you have things here, but bascially BufferedReader will allow you to read from "in" one line at a time. You do not include here what the variable "in" refers to so it is hard to say where the actual data is coming from. But basically using StringBuilder, you are appending, one line at a time the String data from the BufferedReader into the StringBuilder which you can use to get the final string once the entire buffer has been read.

Also check this post out,

Reading Text File From Server on Android

That will give you an idea of how to connect to your server and get the data from a particular script.

- Ken

Community
  • 1
  • 1
Ken Koch
  • 426
  • 3
  • 12