package com.example.and_2;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.Menu;import android.view.MenuItem;import android.widget.TextView;public class MainActivity extends Activity {private  TextView  tv1;private String  result_weather="";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tv1=(TextView)findViewById(R.id.tv1);tv1.setText(read());}public String  read() {StringBuilder sb = new StringBuilder();String data,str;BufferedReader br;try {InputStream input = getResources().openRawResource(R.raw.invalid_weather);//BufferedReader read = new BufferedReader(new InputStreamReader(input));br = new BufferedReader(new InputStreamReader(input,"GBK"));/////UTF-8也是亂碼while ((data = br.readLine()) != null) // 判断最后一行不存在,为空结束循环{// System.out.println(data);//原样输出读到的内容sb.append(data);sb.append("\r\n");}br.close();str=sb.toString();//System.out.println(str);Log.i("str", str);return str;} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return "";}}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="${relativePackage}.${activityClass}" >    <TextView        android:id="@+id/tv1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>


更多相关文章

  1. android:Handler开启线程定时循环
  2. android电话录音
  3. android水平循环滚动控件
  4. Android(安卓)Io 整理
  5. android中IO操作数据总结
  6. %1$s %1$d Android(安卓)string (java & Android(安卓)格式化字符
  7. android单元测试用例和日志输出
  8. Android(安卓)Studio中使用NDK
  9. Android运行底层linux外部命令的实现

随机推荐

  1. android 中给图片加圆角效果
  2. Android API 中文 (112) ―― ThumbnailU
  3. Android Binder机制(三) ServiceManager
  4. Android屏幕截图实现 (adbd部分)
  5. Ubuntu10.04 LTS 下编译Android
  6. Actionbar&Toolbar 自定义Menu 布局--Act
  7. Android的图片压缩类ThumbnailUtils
  8. Android(安卓)修改权限
  9. Android ContentProvider的介绍
  10. Android(安卓)外观模式