我创建了一个名为GpsSession
的{{1}}类的实例,然后调用了uno
。
文件已正确解析,但是创建另一个名为uno.loadSessionFile()
的{{1}}并调用GpsSession
会导致在文件读取和解析期间跳过很多行。我想念什么吗?附加了我的项目的简化(但经过测试)的类,以及测试运行的日志
这是课程:
dos
这是测试运行:
dos.loadSessionFile()
这是创建两个public class GpsSession {
Mainactivity main;
Context context;
String sessionsFolder = Environment.getExternalStorageDirectory() + "/MyFolder/Sessions/";
String sessionFileName;
public GpsSession(Mainactivity _main){
main = _main;
context = main.getapplicationContext();
}
public boolean loadSessionFile(String _fileName){
Log.d("CHRONO","loading " + _fileName);
if(_fileName == null) {
return false;}
File file = new File(sessionsFolder + _fileName);
if(!file.exists()){
Log.d("CHRONO","file don't exists,returning false");
return false;
}
sessionFileName = sessionsFolder + _fileName;
ArrayList <String>storedValues = new ArrayList<>();
BufferedReader br = null;
int lineNumber = 0;
String line;
storedValues.clear();
//copy all the lines to arraylist
try {
br = new BufferedReader( new FileReader(sessionFileName));
while((line = br.readLine()) != null)
{
storedValues.add(line);
Log.d("CHRONO","found line :" + lineNumber);
lineNumber++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(context,context.getString(R.string.file_not_found),Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(context,context.getString(R.string.error_reading_file) + " IO",Toast.LENGTH_LONG).show();
}catch (Exception e) {
e.printStackTrace();
Toast.makeText(context,context.getString(R.string.error_reading_file) + " E",Toast.LENGTH_LONG).show();
}finally {
if(br!=null)
try {
br.close();
} catch(IOException e) {
e.printStackTrace();
}
}
//then parse them in array "parts"
for(int i = 0;i < storedValues.size();i++){
String[] parts = storedValues.get(i).split(",");
Log.d("CHRONO","parsing line--" + i);
if(parts.length > 0) {
Log.d("CHRONO","val= " + parts[0]); }
}
return true;
}
实例的日志示例,并且GpsSession uno = new GpsSession(this);
uno.loadSessionFile("dex.rcs");
GpsSession dos = new GpsSession(this);
dos.loadSessionFile("cip.rcs");
被称为:
请注意第二个文件调用的解析行128,有时是
GpsClass