1.在控制台的Logcat中输出测试语句
package com.example.lucky.helloworld; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class MainActivity extends AppCompatActivity { //当Activityq启动时就会执行onCreate方法 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置activity的内容,内容来自布局文件activity_main.xml setContentView(R.layout.activity_main); Log.v("001","我是verbose级别"); //方法一 Log.i("001","我是info级别"); Log.d("001","我是debug级别"); Log.w("001","我是warn级别"); Log.e("001","我是error级别"); System.out.println("sout输出"); //方法二 } }
2.读取文本文件内容
InputStream input=getResources().openRawResource(R.raw.user);//user是我的文件名,这里应该根据具体文件更改 Reader reader=new InputStreamReader(input); BufferedReader br=new BufferedReader(reader); String str; while ((str=br.readLine())!=null){ System.out.println(str); }