我想把一串字符串写入一个文件中:
private void writeScoreToFile(BlastScore result) { try{ FileWriter fstream = new FileWriter(getFilesDir() + CaptureActivity.BLAST_SCORES,true); BufferedWriter out = new BufferedWriter(fstream); out.write(Integer.toString(result.getBlastScore())); out.close(); }catch (Exception e){ System.err.println("Write Error: " + e.getMessage()); } }
我想把它再作为一个列表读出来。
private List<String> getArrayFromFile(String filename) throws IOException { FileReader fileReader = new FileReader(getFilesDir() + filename); BufferedReader bufferedReader = new BufferedReader(fileReader); List<String> lines = new ArrayList<String>(); String line = null; while ((line = bufferedReader.readLine()) != null) { lines.add(line); } bufferedReader.close(); return lines; }
写入列表中的是:
100 96 100 96 100
打印出的列表却是这样的:
02-26 21:22:31.130: I/System.out(936): Last Score: 1009610096100
打印列表用的是下面的代码:
try { List<String> blastScores = getArrayFromFile(CaptureActivity.BLAST_SCORES); System.out.println("Last Score: " + blastScores.get(blastScores.size()-1)); } catch (IOException e) { // TODO Auto-generated catch block System.err.println("Read Error: " + e.getMessage()); }
请求大家帮忙改正,谢谢。
蓝山帝景
相关分类