[英]Splitting skips half a content when splitting by @
我有一个从文本文件请求数据的android应用程序。 当我尝试分离数据并初始化类时,我遇到了严重的麻烦,因为丢失了分离后一半的数据。 数据源的代码是:
indicators = new ArrayList<Indicator>();
try {
InputStream fileStream = getResources().openRawResource(
R.raw.indicators);
int fileLen = fileStream.available();
// Read the entire resource into a local byte buffer.
byte[] fileBuffer = new byte[fileLen];
fileStream.read(fileBuffer);
fileStream.close();
displayText = new String(fileBuffer);
String[] counts = displayText.split("@");
for(String i: counts) {
String[] temps = i.split(";");
indicators.add(new Indicator(temps[0],temps[1],temps[2]));
}
} catch (IOException e) {
// exception handling
}
for(Indicator i: indicators) Log.v("indicator", i.toString());
指标类的代码可以在这里找到:
public class Indicator {
private String name;
private String isoCode;
private String topic;
public Indicator(String topic, String isoCode,String name) {
this.name = name;
this.isoCode = isoCode;
this.topic = topic;
}
public String getName() {
return this.name;
}
public String getIsoCode() {
return this.isoCode;
}
public String getTopic() {
return this.topic;
}
public String toString() {
return (this.topic + "," + this.isoCode + "," + this.name);
}
}
完成此过程后,以下日志文件中缺少很多内容:
该文件似乎正在跳过其他所有条目,因此,我的整个软件混乱了。 下面的源文件是:
我无法通过修改命令来解决此问题。 但是,通过使用BufferedReader类读取了打开的字符串,我找到了解决此问题的方法。这似乎已经解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.