【发布时间】:2015-05-07 00:39:23
【问题描述】:
我正在尝试读取资产中的 txt 文件。文件的结构是这样的:1 [some text] 1 2 [some text] 2 3 [some text] 3 ...。
我要做的是读取与特定数字对应的[some text] 部分,即如果我传递数字 1,我将从 1 读取到 1。我已经尝试过,但它没有用:
AssetManager manager = this.getAssets();
InputStream input = null;
InputStreamReader in = null;
try {
input = manager.open("facil/alexubago/songlyrics.txt");
in = new InputStreamReader(input);
} catch (IOException e1) {
Log.d("ERROR DETECTED", "ERROR WHILE TRYING TO OPEN FILE");
}
try {
char current;
char current2;
String themessage ="" ;
while (in.ready()) {
final Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roland.ttf");
final TextView extField = (TextView) findViewById(R.id.thelyrics);
extField.setTypeface(tf);
current = (char) in.read();
int a = 1;
char b = (char) a;
if(current == b){
current2 = (char) in.read();
while(current2 != b){
themessage = themessage+current2;}
extField.setText(themessage);
Log.d("caracter", ""+current);}
Toast.makeText(lyricsfreakgame.this,themessage, Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
e.printStackTrace();
}
【问题讨论】: