[英]I have a dynamic text file and want to display its data in table View
我在瀏覽器上有一個文本文件,我想在Android的表格視圖中顯示文本文件數據,在文本文件中有多個變量,並用,(逗號)分隔,變量值用|(管道)分隔,任何人都可以告訴我我如何訪問特定的變量值以在表中顯示它。
String text="";
String[] s;
text=readTxt();
final CharSequence cs = text;
s=cs.toString().split("\\r?\\n? ?\t");
s.toString().trim();
for(int i=0;i<s.length;i++)
{
String temp=s[i].toString();
if(temp.indexOf("yourlabel:")!=-1)
{
try {
temp=temp.substring(temp.indexOf("caption:")+8);
temp.trim();
} catch (Exception e) {
// TODO: handle exception
}
System.out.println("If temp values...."+i+" "+temp);
}
}
private String readTxt(){
File mFile=new File("path/sample.txt");
InputStream inputStream=null;
try {
inputStream = new FileInputStream(mFile);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println(inputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return byteArrayOutputStream.toString();
}
}
這將讀取您的文本文件,“ if(temp.indexOf(“ yourlabel:”)!=-1)“將為您提供特定的標記值,請嘗試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.