使用uiautomator2.0进行测试,将结果写入文件,第2次以后写入报错:System.err,但是没有具体的错误信息。
后来发现是关闭之后没有将FileOutputStream对象置null导致。
public void writeResult(String path,ArrayList<String> arrayList){
path = "sdcard/test/"+path+".txt";
try {
if(bw==null)
bw = new FileOutputStream(path,false);
for(String text : arrayList){
Log.d(TAG, "writeResult: text=" + text);
bw.write(text.getBytes());
bw.flush();
bw.write("\n".getBytes());
bw.flush();
}
//因为关闭了没有置为null所以下次调用时出错
bw.close();
bw = null;
} catch (IOException e) {
e.printStackTrace();
}
}