How to convert a String object to an InputStream object?
ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes());
How do I replace the parameter values in the network URL?
String baseURL = "http://sixweather.3gpk.net/SixWeather.aspx? City = % s "; String cityName =" Wuhan "; String resultURL = String. format (baseURL, cityName );
In Java, how does one access the network address and obtain the returned results?
// *************** Access the network to obtain weather forecast data, store result data to result ********************* // initialize httpGet, pass the url parameter to HttpGet httpGet = new HttpGet (url); String result = ""; // initialize httpClientHttpClient httpClient = new DefaultHttpClient (); // call the execute method of httpClient, returns the HttpResponse instance HttpResponse httpResponse = httpClient.exe cute (httpGet); if (httpResponse. getStatusLine (). getStatusCode () = HttpStatus. SC _ OK) {// convert the weather data in httpResponse to the string format result = EntityUtils. toString (httpResponse. getEntity ());} //************************************** **************************************** **********
How to encode and decode String in Java?
String cityName = "Wuhan"; try {// perform UTF-8 encoding for cityName = URLEncoder. encode (cityName, "UTF-8"); // perform UTF-8 Decoding for cityName. cityName = URLDecoder. decode (cityName, "UTF-8");} catch (Exception e) {e. printStackTrace ();}