我試圖讓從file
文本,並將其應用到textView
在TextView中顯示它。但是,如下所示,我將以file path
返回。讀txt文件,並在不同的片段/活性
@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