您的位置:首页 > 移动开发 > Android开发

android 获取配置文件信息

2013-08-05 03:06 441 查看
public class MainActivity extends Activity {
private EditText myquestion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** 全屏设置,隐藏窗口所有装饰 */
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Log.d("Show main page.","ok");

myquestion=(EditText)findViewById(R.id.editTextQuestion);
AssetManager assetManager = getAssets();
InputStream inputStream = null;
try {
  inputStream = assetManager.open("questions.txt");
 } catch (IOException e) {
  Log.e("tag", e.getMessage());
 }
String s = readTextFile(inputStream);
myquestion.setText(s);

}

private String readTextFile(InputStream inputStream) {
 String outputStream = new String();
 byte buf[] = new byte[1024];
 int len;
 try {
  while ((len = inputStream.read(buf)) != -1) {
   outputStream =  outputStream + EncodingUtils.getString(buf,"UTF-8");
  }
  inputStream.close();
 } catch (IOException e) {
 }
 return outputStream;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: