Possible Duplicate:
Not Reading text from server
i am trying to read text from a .txt file which is present on server but my code is not reading text from file i am using android version 2.1 , will you please also tell me how can i handle the exception in order to caught the error.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv= new TextView(this);
StringBuilder content = new StringBuilder();
try {
URL url = new URL("http://linktomywebsite/textfile.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
content.append(str +"\n");
tv.setText(content);
}
in.close();
} catch (MalformedURLException e){
} catch (IOException e) {
e.printStackTrace();
}
};