您好我正在尝试显示文件中的信息:
由于某种原因,我使用的第一个文件(temp.txt)有效,我得到了这个输出
Your Body Temperature Readings are: 36.2
32
37.d
我的temp.txt文件
36.2
32
37.d
然而,我发送到手机的任何其他文件(通过蓝牙)然后尝试使用应用程序读取都没有输出,我做错了什么?
例如,我发送了另一个文件temppp.txt,其中包含以下信息,我得到了输出:
Your Body Temperature Readings are:
my temppp.txt
37.06750839
36.89390613
36.88484785
36.81941363
36.81815453
这是我按下按钮单击调用的类,并打开一个包含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);
}