我的代码之前用逗号分隔时运行良好,现在它不适用于分号!
用逗号:
public void loadXXXData() {
InputStream is = getResources().openRawResource(R.raw.xxxdata);
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
String line;
String[] RowData;
RowData = new String[XXXVARNUM];
for(int i=0;i<NUMBEROFXXX;i++){
//Read the line.
line = reader.readLine();
//Cut the line up.
RowData = line.split(",",XXXVARNUM);
for(int j=0;j<XXXVARNUM;j++){
//Distribute the line into a 2D array.
XXX[i][j] = RowData[j];
}
}
//Populate forms
setCurrentXXX(XXX);
}
catch (IOException ex) {
Log.v("XXXdex", "I/O Exception: Could not read from the I/O stream.");
}
finally {
try {
//Close the stream
is.close();
}
catch (IOException e) {
Log.v("XXXdex", "I/O Exception: Could not close the I/O stream.");
}
finally {
}
}
}
finally {
}
}
按分号:
public void loadItemData() {
InputStream is = getResources().openRawResource(R.raw.items);
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
String line;
String[] RowData;
RowData = new String[ITEMVARNUM];
for(int i=0;i<NUMBEROFITEMS;i++){
//Read the line.
line = reader.readLine();
//Cut the line up.
RowData = line.split(";",ITEMVARNUM);
for(int j=0;j<ITEMVARNUM;j++){
//Distribute the line into a 2D array.
ITEM[i][j] = RowData[j];
}
}
//Populate forms
setCurrentItem(item);
}
catch (IOException ex) {
Log.v("XXXdex", "I/O Exception: Could not read from the I/O stream.");
}
finally {
try {
//Close the stream
is.close();
}
catch (IOException e) {
Log.v("XXXdex", "I/O Exception: Could not close the I/O stream.");
}
finally {
}
}
}
finally {
}
}
来自 xxxData 的样本:
1,dinosaur,Grass,Poison,45,49,49,65,65,45,Supergrow,,DrPhyll,64,0,0,0,1,0,0,45,0.7 m,6.9 kg,Seed
...完美加载。
itemData 的示例:
Antidote;A spray-type medicine. It lifts the effect of poison from one XXX.;Route 3, Pinwheel Forest, Pinwheel Forest, Pinwheel Forest (With Dowsing Machine), Icirrus City Shop Route 9, Accumula Town, Striaton City, Nacrene City, Castelia City, Nimbasa City, Driftveil City, Mistralton City, Icirrus City, Opelucid City, XXX League, Lacunosa Town, Undella Town, Black City, White Forest
...不会正确拆分。那是怎么回事?我搜索了论坛寻找代表“;”的正则表达式,但没有任何效果。我不断收到 arrayIndexOutOfBounds 异常,因为 String.split 没有将我的字符串分成正确数量的字符串。