Hi, you should try something like URL myURL = new URL("http://lol.com/lol.txt"); URLConnection conn = myURL.openConnection(); conn.connect(); BufferedReader is = new BufferedReader(new InputStreamReader (conn.getInputStream(), "UTF8")); FileOutputStream fOut = openFileOutput("lol.txt", MODE_WORLD_READABLE); OutputStreamWriter osw = new OutputStreamWriter(fOut, "UTF8"); String istr; while ((istr = is.readLine()) != null) osw.write(istr+"\n"); osw.close();
This download the http://lol.comlol.txt file to lol.txt local file Also check the DDMS LogCat tab for where your error is. 2009/3/21 murphy <howt...@hotmail.com>: > > Hi all, I am having difficulty retrieving data from the internet to be > displayed in a TextView. When I run the application it says the > application has stopped unexpectedly. I am using the code: > > String urls = "http://www.indulec.ie/weather.txt"; > > HttpClient client = new DefaultHttpClient(); > > // Create a method instance. > HttpGet method = new HttpGet(urls); > method.getParams().setIntParameter > (CoreConnectionPNames.CONNECTION_TIMEOUT, 10000 ); > method.getParams().setIntParameter > (CoreConnectionPNames.SO_TIMEOUT, 10000 ); > method.getParams().setIntParameter > (CoreConnectionPNames.SOCKET_BUFFER_SIZE, 200000 ); > method.getParams().setIntParameter > (ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, 5 ); > method.getParams().setIntParameter > (ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 10 ); > > HttpResponse response = null; > InputStream input = null; > > try > { > response = client.execute( method ); > HttpEntity entity = response.getEntity(); > input = entity.getContent(); > > > > TextView tv = (TextView)findViewById(R.id.somenews); > tv.setText((CharSequence) input); > > setContentView(R.layout.latestnews); > > > } > catch ( IOException e ) > { > Log.d("", "Can not connect to the target server!" ); > try { > throw new IOException(); > } catch (IOException e1) { > // TODO Auto-generated catch block > e1.printStackTrace(); > } > } > finally > { > Log.d("", "close Expired Connections!" ); > client.getConnectionManager().closeExpiredConnections > (); > } > > > > -- Lliane aka Simon Depiets Epita Promo 2011,42 http://www.lliane.com A man is smoking with his girlfriend. She angers herself : "don't you see the warning on the box ?!" To which the man replies, "I am a programmer. I don't worry about warnings. I only worry about errors." --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---