您好我有一个包含由逗号和空格例如,分号文件:阅读文件,以int数组
[ 0, 1, 1, 1, 0,
0, 0, 1, 0, 1 ]
读他们以此来int数组IM:
InputStream is = null;
try {
file = new int[20][20];
is = activity.getAssets().open(f);
for (int i = 0;i < file.length; i++)
for(int j = 0; j < file[i].length; j++) {
file[i][j] = Character.getNumericValue(is.read());
is.read();
is.read();
}
} catch (Exception e) {
Log.i("file", "exception: " + e);
但如果我有更高的数字像12例如:
[ 0, 1, 10, 10, 0,
0, 0, 12, 0, 11 ]
如何将其读取到数组?
读取一个字符串并使用String.split(甚至,如果您碰巧注意到这是一个有效的JSON格式,则从您的字符串中获得一个JSONArray) – njzk2 2013-04-29 09:26:54