Hi I am trying to display the information from a file:
For some reason the first file I used(temp.txt) works and I get this output
Your Body Temperature Readings are: 36.2
32
37.d
my temp.txt file
36.2
32
37.d
however any other file that I send to my phone(via bluetooth) and then try and read with the app presents no output, what am I doing wrong?
For example I sent another file temppp.txt with information below and I got the output:
Your Body Temperature Readings are:
my temppp.txt
37.06750839
36.89390613
36.88484785
36.81941363
36.81815453
Here is my class which is called on a button click and opens up a new view that has the bodyTempInfoArray textview.
package com.teamfara.circadianrhythmmonitor4;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class bodyTempInfo extends AppCompatActivity {
ArrayList<Double> currentBodyTemp;
private void displayBodyTemp(String bodyTemp) {
TextView textView = (TextView) findViewById(R.id.bodyTempInfoArray);
textView.setText(bodyTemp);
}
public void displayCurrentBodyTempArray(View view) throws FileNotFoundException {
ArrayList<Double> list = new ArrayList<>();
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
//Read text from file
File file = new File(sdcard, "temppp.txt");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
list.add(Double.parseDouble(line));
text.append(line);
text.append('\n');
}
br.close();
}
catch(IOException e) {
}
currentBodyTemp = list;
displayBodyTemp("Your Body Temperature Readings are: " + text);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_body_temp_info);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
try {
displayCurrentBodyTempArray(findViewById(R.id.bodyTempInfoArray));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}