public static void main(String arg[]) {
try {
String encoding = "UTF-8"; // 字符编码GBK,GB2312(可解决中文乱码问题 )
File file = new File("c:/aa.txt");
if (file.isFile() && file.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
String allNumString = "";
int[] array = null;
while ((lineTXT = bufferedReader.readLine()) != null) {
// 读出的每一行
System.out.println(lineTXT.toString().trim());
allNumString += lineTXT+",";
}
if(allNumString != null && !"".equals(allNumString)){
String[] numbers = allNumString.split(",");
array = new int[numbers.length];
for (int i = 0; i < numbers.length; i++) {
array[i] = Integer.parseInt(numbers[i]);
}
}
for (int i = 0; i < array.length; i++) {
System.out.println("数组["+i+"]:"+array[i]);
}
read.close();
} else {
System.out.println("找不到指定的文件!");
}
} catch (Exception e) {
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
}
追问读取文件内容操作出错
java.lang.NumberFormatException: For input string: "33 29 8 48 4 37 10 31 0 21 1 15 49 20 28 19 34 35 2 27 30 7 25 6 42 23 22 47 5 26 50 45 11 36 16 3 46 17 13 24 12 40 18 39 41 43 14 44 32 38 9 33 "
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
。。。
能存进去,但是出错哦,怎么解决呢
追答囧啊 用空格隔开 我看成是 ,