【发布时间】:2017-04-08 18:25:01
【问题描述】:
public class intro extends AppCompatActivity {
private StringBuilder text = new StringBuilder();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intro);
BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(getAssets().open("assets/Introduction.txt")));
// do reading, usually loop until end of file reading
String mLine;
while ((mLine = reader.readLine()) != null) {
text.append(mLine);
text.append('\n');
}
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error reading file!", Toast.LENGTH_LONG).show();
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
//log the exception
}
}
TextView output= (TextView) findViewById(R.id.intro);
output.setText((CharSequence) text);
}
}
[This is my project explorer][1]}
我尝试了很多打开 assets 文件夹的路径,但它显示 filenotfound 异常。这里我在 Assets 文件夹中创建了 Introduction.txt 文件并在上面写了一些内容。但是我无法通过提供路径或文件名来打开它。
【问题讨论】:
标签: android listview android-fragments