我正在开发一款Android App,一本书。这是一个很长的内容段落。我正在考虑将该段落分成小段并使用SQLite
数据库将它们存储在数据库中,方法是创建一个包含以下属性的表:ID
,Title
,Path
,. ..我将这些小段存储在文本文件中并将它们复制到手机目录中。我想问一下,我们可以通过电话簿中的路径访问这些文件吗?如果是,那该怎么办?
答案 0 :(得分:0)
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard,"file.txt");
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.text_view);
//Set the text
tv.setText(text);
我希望它对你有用..