源码如下:
public static int LastScore;public File sdcard = Environment.getExternalStorageDirectory();public File file = new File(sdcard,"sample.txt"); try{ BufferedReader br = new BufferedReader(new FileReader(file)); String line = null; line = br.readLine(); if(line!=null){ LastScore = Integer.parseInt(line); } }catch (IOException e){ System.err.println(e); }
出现问题java.lang.numberformatexception invalid int “”的代码:
line = br.readLine();LastScore = Integer.parseInt(line);
修改方法:
line = br.readLine();if(line != null){ LastScore = Integer.parseInt(line); line = br.readLine();}