file
からテキストを取得し、textView
に適用しようとしています。しかし、私はfile path
と返されています。txtファイルを読み込んで、異なるフラグメント/アクティビティのtextViewに表示する
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
tv = (TextView) getActivity().findViewById(R.id.clockText);
// Displaying the user details on the screen
try {
getFileText();
} catch (IOException e) {
e.printStackTrace();
}
}
public void getFileText() throws IOException {
File path = getActivity().getExternalFilesDir(null); //sd card
File file = new File(path, "alarmString.txt"); //saves in Android/
FileInputStream stream = new FileInputStream(file);
try{
stream.read();
tv.setText(file.toString());
} finally {
stream.close();
}
}
結果ではなく、時間の"Android/data/foldername/example/files/alarmString.txt"
は、例えば、異なる活動にユーザによって宣言されている:18:05