0
我试图读取资产中的txt文件。该文件的结构如下所示:1 [some text] 1 2 [some text] 2 3 [some text] 3 ...
。 我想要做的是阅读[some text]
部分对应于一个特定的数字,即如果我通过数字1,我会从1读到1.我试过这个,但它没有工作:Android:将文件从特定字符读取到另一个特定字符
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();
}
的int a = 1时只是测试它像 –
给使用INT A = 1,您要1块(1【正文】1内读取文本的给定数量的心不是), 对? – sabbir