public class MainActivity extends Activity { private static final String TAG = "read"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.btn_read_txt).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { InputStream is = getResources().getAssets().open("info.txt"); InputStreamReader isr = new InputStreamReader(is,"UTF-8");//显示规定编码是好习惯,免得乱码. BufferedReader br = new BufferedReader(isr); String lineData = ""; while((lineData = br.readLine()) != null){ Log.i(TAG, lineData); } } catch (IOException e) { e.printStackTrace(); } } }); } }
时间: 2024-11-09 11:53:25