I've solved my own issue but I don't know why my first attempt didn't work and I was hoping someone could tell me why. I was also hoping if someone could tell me if my final solution is a "good" one or not (by this I mean, is it efficient)?
This was my first attempt at reading an input file I had previously created:
private byte[] mInputData;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_view);
Intent myIntent = getIntent();
mFilename = myIntent.getStringExtra("FILENAME");
mSplitSeq = myIntent.getStringExtra("SPLIT_SEQ");
try {
fis = openFileInput(mFilename);
fis.read(mInputData);
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
This is something I found online that actually worked:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_view);
Intent myIntent = getIntent();
mFilename = myIntent.getStringExtra("FILENAME");
mSplitSeq = myIntent.getStringExtra("SPLIT_SEQ");
try {
fis = openFileInput(mFilename);
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line = null, input="";
while ((line = reader.readLine()) != null)
mTimeStr += line;
reader.close();
fis.close();
//fis.read(mInputData);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
The error I received with my first implementation was a NullPointerException when calling the fis.read(mInputData) function.